在OneVsallClassifier中使用svc模型时出错

时间:2018-09-04 08:36:41

标签: python-3.x scikit-learn

from sklearn.multiclass import OneVsRestClassifier
from sklearn.svm import SVC

classifier = SVC(C=100, # penalty parameter, setting it to a larger value 
             kernel='rbf', # kernel type, rbf working fine here
             degree=3, # default value, not tuned yet
             gamma=1, # kernel coefficient, not tuned yet
             coef0=1, # change to 1 from default value of 0.0
             shrinking=True, # using shrinking heuristics
             tol=0.001, # stopping criterion tolerance 
             probability=False, # no need to enable probability estimates
             cache_size=200, # 200 MB cache size
             class_weight=None, # all classes are treated equally 
             verbose=False, # print the logs 
             max_iter=-1, # no limit, let it run
             decision_function_shape=None, # will use one vs rest explicitly 
             random_state=None)

model = OneVsRestClassifier(classifier, n_jobs=4)
model.fit(X_train,y_train)

我收到此错误:

  

ValueError:WRITEBACKIFCOPY基为只读。

1 个答案:

答案 0 :(得分:0)

请在训练模型之前对输入数据进行缩放,即 OneVsRestClassifier。 例如。

from sklearn.preprocessing import MinMaxScaler #if its a dense matrix else use MaxAbsScaler in case of sparse matrix
scaler = MinMaxScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

classifier = SVC(C=100, # penalty parameter, setting it to a larger value 
             kernel='rbf', # kernel type, rbf working fine here
             degree=3, # default value, not tuned yet
             gamma=1, # kernel coefficient, not tuned yet
             coef0=1, # change to 1 from default value of 0.0
             shrinking=True, # using shrinking heuristics
             tol=0.001, # stopping criterion tolerance 
             probability=False, # no need to enable probability estimates
             cache_size=200, # 200 MB cache size
             class_weight=None, # all classes are treated equally 
             verbose=False, # print the logs 
             max_iter=-1, # no limit, let it run
             decision_function_shape=None, # will use one vs rest explicitly 
             random_state=None)

model = OneVsRestClassifier(classifier, n_jobs=-1)
model.fit(X_train,y_train)