ValueError: 找到带有暗淡 3 的数组.估计器预期 <= 2.>>> [英] ValueError: Found array with dim 3. Estimator expected <= 2. >>>
本文介绍了ValueError: 找到带有暗淡 3 的数组.估计器预期 <= 2.>>>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#Import Library
from sklearn import svm
import numpy as np
X=np.array([
[[25,25,25],[0,0,0],[0,0,0]],
[[25,0,0],[25,0,0],[25,0,0]],
[[75,75,75],[75,75,75],[75,75,75]]
])
y=np.array([-1,1,1]
)
C=10
model = svm.SVC(kernel='rbf', C=10, gamma=0.6)
model.fit(X, y)
model.score(X, y)
当我尝试运行此代码时,出现此错误
when I tried to run this code , I got this error
ValueError: 发现数组,dim 为 3.估计器预期 <= 2.
ValueError: Found array with dim 3. Estimator expected <= 2.
我希望你能帮我解决这个错误.我想训练 svm 将图像像素分为两类(边缘和非边缘),任何建议都会有所帮助,提前致谢
I would like that you help me solve this error. I want to train the svm to classify image pixels into two classes (edge and non-edges ), any suggestions will be helpful thanks in advance
推荐答案
我不知道问题域.但这可以解决您的错误,
I don't know about problem domain. But this solves your error,
#Import Library
from sklearn import svm
import numpy as np
X=np.array([
[[25,25,25],[0,0,0],[0,0,0]],
[[25,0,0],[25,0,0],[25,0,0]],
[[75,75,75],[75,75,75],[75,75,75]]
])
X = X.reshape(X.shape[0], -1)
y=np.array([-1,1,1])
C=10
model = svm.SVC(kernel='rbf', C=10, gamma=0.6)
model.fit(X, y)
model.score(X, y)
输出:
1.0
这篇关于ValueError: 找到带有暗淡 3 的数组.估计器预期 <= 2.>>>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文