机器学习(六)之数据归一化

第一,话不多说,先上网址,自行查看一下https://scikit-learn.org/stable/modules/preprocessing.html#preprocessing

Jupyter Notebook
数据归一化
最后检查: 5 分钟前
(未保存改变)
Current Kernel Logo
Python 3 
File
Edit
View
Insert
Cell
Kernel
Widgets
Help


import numpy as np
from sklearn import datasets
from sklearn.model_selection import train_test_split
import numpy as np
from sklearn import datasets
from sklearn.model_selection import train_test_split

iris = datasets.load_iris()

X = iris.data
Y = iris.target
X = iris.data
Y = iris.target

进行数据的分割

X,Y
X_train,X_test,Y_train,Y_test = train_test_split(X,Y)

​
数据做好,进行数的归一化


from sklearn import preprocessing

scaler = preprocessing.StandardScaler().fit(X_train)

X_train_standation = scaler.transform(X_train)
X_train_standation = scaler.transform(X_train)

​

X_test_standation = scaler.transform(X_test)

进行测试啦

from sklearn.neighbors import KNeighborsClassifier
knn_clf = KNeighborsClassifier(n_neighbors=3)

knn_clf.fit(X_train_standation,Y_train)
KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',
           metric_params=None, n_jobs=None, n_neighbors=3, p=2,
           weights='uniform')

knn_clf.score(X_test_standation,Y_test)
0.9210526315789473

#说过实话,得出的结果有点差强人意​,照道理不应该有1吗????

猜你喜欢

转载自blog.csdn.net/qq_37982109/article/details/87905658