将 svc 模型与 onevsallclassifier 结合使用时出现错误

Vic*_*c13 6 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)
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

ValueError:WRITEBACKIFCOPY 基础是只读的。

小智 -1

请在训练模型(即 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)
Run Code Online (Sandbox Code Playgroud)