# 数据标准化模块
from sklearn import preprocessing
# 将资料分割成train与test的模块
from sklearn.model_selection import train_test_split
# 生成适合做classification资料的模块
from sklearn.datasets._samples_generator import make_classification
# Support Vector Machine中的Support Vector Classifier
from sklearn.svm import SVC
# 可视化数据的模块
import matplotlib.pyplot as plt
import numpy as np
# 生成适合做Classification数据,生成具有2种属性的300笔数据
x, y = make_classification(
n_samples=300,
n_features=2,
n_redundant=0,
n_informative=2,
random_state=22,
n_clusters_per_class=1,
scale=100
)
# print(x)
# plt.scatter(x[:,0],x[:,1],c=y)
# plt.show()
# 标准化前的预测准确率 0.9
# x_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.96
x = preprocessing.scale(x)
x_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))
sklearn做Normalization正则化
最新推荐文章于 2024-02-22 10:10:41 发布