normalization数据标准化

from __future__ import print_function
from sklearn import preprocessing
from sklearn.cross_validation import train_test_split
from sklearn.datasets.samples_generator import make_classification
from sklearn.svm import SVC
import matplotlib.pyplot as plt

# n_samples=300表示有300个样例,n_features=2表示有2个特征,
# n_informative=2表示有2个比较相关的属性,random_state=22表示数据是随机产生的,但每次run时产生的data是一样的
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)
# scatter表示用点绘图
plt.scatter(X[:, 1], X[:, 0], c=y)
plt.show()

# # normalization处理后的输出,feature_range=(0,1)把值处理到01这个范围
# X = preprocessing.minmax_scale(X,feature_range=(0,1))
X = preprocessing.scale(X)
# train_test_split把数据切分成训练集和测试集,训练集占70%
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.3)
clf = SVC()
clf.fit(X_train, y_train)
# 对预测进行打分,用data_X预测的值和data_y进行对比
print(clf.score(X_test, y_test))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值