我对这段代码有疑问:
from sklearn import svm
model_SVC = SVC()
model_SVC.fit(X_scaled_df_train, y_train)
svm_prediction = model_SVC.predict(X_scaled_df_test)
错误信息是
名称错误
回溯(最近一次调用 最后)~\AppData\Local\Temp/ipykernel_14392/1339209891.py 中 ----> 1 svm_prediction = model_SVC.predict(X_scaled_df_test)名称错误:名称“model_SVC”未定义
有什么想法吗?
用途:
from sklearn.svm import SVC
from sklearn import svm
行不正确。正确的做法是
from sklearn.svm import SVC
文档是sklearn.svm.SVC。当我选择这个模型时,我会注意数据集的大小。摘录:
拟合时间至少与样本数量呈二次方关系,超过数万个样本可能不切实际。对于大型数据集,请考虑使用 LinearSVC 代替。
from sklearn.svm import LinearSVC
有关更多信息,您可以阅读何时应该使用 LinearSVC 或 SVC?
我在tutorialspoint.com的帮助下编码时发现了这篇文章,在那里我学习了svm及其在人工智能中的Python实现中的用法。 代码是
Svc_classifier = svm_classifier.SVC(kernel='linear',
C=C, decision_function_shape = 'ovr').fit(X, y)
Z = svc_classifier.predict(X_plot)
Z = Z.reshape(xx.shape)
修改后的代码将是
svc_classifier = svm.SVC(kernel='linear',
C=C, decision_function_shape = 'ovr').fit(X, y)
Z = svc_classifier.predict(X_plot)
Z = Z.reshape(xx.shape)