正交化 Normalization
数据标准化
preprocessing.scale( ) preprocessing.minmax_scale(X,feature_range=(0,1) ): feature_range是设置数据标准化后数据的范围,默认为0~1 1
2
3
4
5
6
7
8
9
10
11
12
13
14from sklearn import preprocessing #标准化数据模块
import numpy as np
#建立Array
a = np.array([[10, 2.7, 3.6],
[-100, 5, -2],
[120, 20, 40]], dtype=np.float64)
# 打印出原来的a
print(a)
#将normalized后的a打印出
print(preprocessing.scale(a))
# [[ 0. -0.85170713 -0.55138018]
# [-1.22474487 -0.55187146 -0.852133 ]
# [ 1.22474487 1.40357859 1.40351318]]
加载模块
1 |
|
生成数据-生成适合做Classification数据
1 | #生成具有2种属性的300笔数据 |
### 训练数据 1
2
3
4
5X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
clf = SVC()
clf.fit(X_train, y_train)
print(clf.score(X_test, y_test))
# 0.477777777778
标准化数据及可视化
1 | X = preprocessing.scale(X) |