1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
from sklearn.metrics import classification_report from sklearn import preprocessing from sklearn.cross_validation import train_test_split from sklearn.model_selection import GridSearchCV from sklearn.multiclass import OneVsOneClassifier from sklearn.multiclass import OneVsRestClassifier import pandas as pd
data_path='./winequality-red.csv'
data=pd.read_csv(data_path,delimiter=';')
data_src=data.iloc[:,:11] data_tar=data.iloc[:,11:]
X_train, X_test, Y_train, Y_test=train_test_split(data_src,data_tar,test_size=0.20,random_state=33) ss = StandardScaler()
X_train = ss.fit_transform(X_train) X_test = ss.transform(X_test)
grid = GridSearchCV(SVC(), param_grid={"C":[0.1,0.5,1,5,10], "gamma": [1,0,5,0.1,0.05, 0.01]}, cv=4) grid.fit(X, y) print("The best parameters are %s with a score of %0.2f" % (grid.best_params_, grid.best_score_))
csvm = svm.SVC(C=0.5, kernel="rbf", degree=3, gamma=1, coef0=0.0, shrinking=True, probability=False, tol=0.001, cache_size=200)
Y_predict=OneVsOneClassifier(csvm).fit(X_train,Y_train).predict(X_test)
print classification_report(Y_test, Y_predict)
|