gpt4 book ai didi

python - 使用 OneVsRestClassifier 时全为零

转载 作者:行者123 更新时间:2023-11-30 09:11:45 26 4
gpt4 key购买 nike

我正在尝试在我的数据集上使用 OneCsRestClassifier。我提取了将要训练的模型的特征,并在其上安装了线性 SVC。模型拟合后,当我尝试预测模型拟合的相同数据时,我得到的全是零。是因为一些实现问题还是因为我的特征提取不够好。我认为,由于我是根据模型所拟合的相同数据进行预测,因此我应该获得 100% 的准确度。但相反,我的模型预测全为零。这是我的代码-

#arrFinal contains all the features and the labels. Last 16 columns are labels and features are from 1 to 521. 17th column from the last is not taken
X=np.array(arrFinal[:,1:-17])
X=X.astype(float)
Xtest=np.array(X)

Y=np.array(arrFinal[:,522:]).astype(float)
clf = OneVsRestClassifier(SVC(kernel='linear'))
clf.fit(X, Y)
ans=clf.predict(Xtest)
print(ans)
print("\n\n\n")

我的 OneVsRestClassifier 实现有问题吗?

最佳答案

查看您的数据后,这些值对于 C 值来说可能太小。尝试使用sklearn.preprocessing.StandardScaler

X=np.array(arrFinal[:,1:-17])
X=X.astype(float)
scaler = StandardScaler()
X = scaler.fit_transform(X)
Xtest=np.array(X)

Y=np.array(arrFinal[:,522:]).astype(float)
clf = OneVsRestClassifier(SVC(kernel='linear', C=100))
clf.fit(X, Y)
ans=clf.predict(Xtest)
print(ans)
print("\n\n\n")

从这里开始,您应该使用交叉验证来了解 C 上的参数调整。使用学习曲线或使用网格搜索。

关于python - 使用 OneVsRestClassifier 时全为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34477742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com