使用preprocessing将一些变化幅度较大的特征化到[-1,1]之内。

  • 与数据
print(train_df['Age'].head())
  • 输出
0    22.0
1    38.0
2    26.0
3    35.0
4    35.0
  • 特征化处理
import sklearn.preprocessing as preprocessing

scaler = preprocessing.StandardScaler()
x = train_df['Age'].values.reshape(-1,1) 
age_scale_param = scaler.fit(x) # 必须是列数为1的数组
train_df['Age_scaled'] = scaler.fit_transform(x, age_scale_param)
print(train_df['Age_scaled'])
  • 输出
0     -0.561380
1      0.613171
2     -0.267742
3      0.392942
4      0.392942

猜你喜欢

转载自www.cnblogs.com/rener0424/p/11331002.html
今日推荐