from sklearn.datasets import load_digits
from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.svm import LinearSVC
from sklearn.metrics import classification_report
digits = load_digits()#载入数据
X_train,X_test,y_train,y_test=train_test_split(digits.data,digits.target,test_size=0.25,random_state=33)#划分样本75%为训练数据25%为测试数据
print(y_train.shape)
print(y_test.shape)
#对训练数据和测试数据进行标准化
ss = StandardScaler()
X_train = ss.fit_transform(X_train)
X_test = ss.transform(X_test)
#进行初始化线性假设的支持向量分类器LinearSVC
lsvc =LinearSVC()
lsvc.fit(X_train,y_train)
y_predict = lsvc.predict(X_test)
#使用模型自带的评估函数进行准确性预测
print('The Accurancy of Linear SVC is',lsvc.score(X_test,y_test))
print(classification_report(y_test,y_predict,target_names=digits.target_names.astype(str)))
from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.svm import LinearSVC
from sklearn.metrics import classification_report
digits = load_digits()#载入数据
X_train,X_test,y_train,y_test=train_test_split(digits.data,digits.target,test_size=0.25,random_state=33)#划分样本75%为训练数据25%为测试数据
print(y_train.shape)
print(y_test.shape)
#对训练数据和测试数据进行标准化
ss = StandardScaler()
X_train = ss.fit_transform(X_train)
X_test = ss.transform(X_test)
#进行初始化线性假设的支持向量分类器LinearSVC
lsvc =LinearSVC()
lsvc.fit(X_train,y_train)
y_predict = lsvc.predict(X_test)
#使用模型自带的评估函数进行准确性预测
print('The Accurancy of Linear SVC is',lsvc.score(X_test,y_test))
print(classification_report(y_test,y_predict,target_names=digits.target_names.astype(str)))