在 sklearn 中预测训练数据
Predict training data in sklearn
我像这样使用 scikit-learn 的 SVM:
clf = svm.SVC()
clf.fit(td_X, td_y)
我的问题是,当我使用 classifier 来预测训练集成员的 class 时,即使在 scikit-learns 中,classifier 也会出错吗执行。 (例如 clf.predict(td_X[a])==td_Y[a]
)
是的,运行 例如这个代码:
from sklearn import svm
import numpy as np
clf = svm.SVC()
np.random.seed(seed=42)
x=np.random.normal(loc=0.0, scale=1.0, size=[100,2])
y=np.random.randint(2,size=100)
clf.fit(x,y)
print(clf.score(x,y))
得分为 0.61,因此近 40% 的训练数据被错误分类。部分原因是即使默认内核是 'rbf'
(理论上它应该能够完美地分类任何训练数据集,只要你没有两个具有不同标签的相同训练点),那里也是正则化以减少过拟合。默认正则化器是 C=1.0
.
如果您 运行 使用与上述相同的代码,但将 clf = svm.SVC()
切换为 clf = svm.SVC(C=200000)
,您将获得 0.94 的准确度。
我像这样使用 scikit-learn 的 SVM:
clf = svm.SVC()
clf.fit(td_X, td_y)
我的问题是,当我使用 classifier 来预测训练集成员的 class 时,即使在 scikit-learns 中,classifier 也会出错吗执行。 (例如 clf.predict(td_X[a])==td_Y[a]
)
是的,运行 例如这个代码:
from sklearn import svm
import numpy as np
clf = svm.SVC()
np.random.seed(seed=42)
x=np.random.normal(loc=0.0, scale=1.0, size=[100,2])
y=np.random.randint(2,size=100)
clf.fit(x,y)
print(clf.score(x,y))
得分为 0.61,因此近 40% 的训练数据被错误分类。部分原因是即使默认内核是 'rbf'
(理论上它应该能够完美地分类任何训练数据集,只要你没有两个具有不同标签的相同训练点),那里也是正则化以减少过拟合。默认正则化器是 C=1.0
.
如果您 运行 使用与上述相同的代码,但将 clf = svm.SVC()
切换为 clf = svm.SVC(C=200000)
,您将获得 0.94 的准确度。