Skip to content Skip to sidebar Skip to footer

Valueerror: Found Array With Dim 3. Estimator Expected <= 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

Solution 1:

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)

Output:

1.0

Solution 2:

model.fit needs 2D array but your X is 3D. Convert Your X into 2D using np.concatenate

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]
           )


X = [np.concatenate(i) for i in X]
print(X)
model = svm.SVC(kernel='rbf', C=10, gamma=0.6) 


model.fit(X, y)
model.score(X, y)

Post a Comment for "Valueerror: Found Array With Dim 3. Estimator Expected <= 2. >>>"