阅读前请看一下:我是一个热衷于记录的人,每次写博客会反复研读,尽量不断提升博客质量。文章设置为仅粉丝可见,是因为写博客确实花了不少精力。希望互相进步谢谢!!
文章目录
1、问题描述:
背景:机器学习时关于SVM的学习
函数:svm.SVC中的 fit() 函数
code:
# SVM训练与预测
res = svm.SVC(C=svm_C, kernel=svm_kernel)
res.fit(train_set_X.T, train_set_y.T) #训练
bug:
DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
2、原因分析:
首先通过提示即可知道原因;
其次看函数说明也可以知道;
3、解决方案:
二维转一维即可,四个方案选其一。
reshape(-1)
flatten()
ravel()
squeeze()
# SVM训练与预测
res = svm.SVC(C=svm_C, kernel=svm_kernel)
res.fit(train_set_X.T, train_set_y.T.reshape(-1)) #训练
# res.fit(train_set_X, train_set_y.T.flatten()) #训练
# res.fit(train_set_X, train_set_y.T.ravel()) #训练
# res.fit(train_set_X, np.squeeze(train_set_y.T)) #训练
码字不易,谢谢点赞!!!
码字不易,谢谢点赞!!!
码字不易,谢谢点赞!!!
文章出处登录后可见!
已经登录?立即刷新