Issue
Error : Found input variables with inconsistent numbers of samples: [15, 5]
i am creating an sklearn pipeline as i wanted to scale using standard scaler and then i am creating an svm model. only to check how good is my model.
shape of x = 20,4096
X_train, X_test, Y_train, Y_test = train_test_split(x , y, random_state = 0)
pipe = Pipeline([('scaler', StandardScaler()), ('svc', SVC(kernel = 'rbf', C = 10))])
pipe.fit(X_train, Y_test)
pipe.score(X_test, Y_test)
Solution
import sklearn
import sklearn.datasets
import sklearn.ensemble
import numpy as np
from sklearn.pipeline import Pipeline
from sklearn.svm import SVC
from sklearn.preprocessing import StandardScaler
iris = sklearn.datasets.load_iris()
X_train, X_test, Y_train, Y_test = sklearn.model_selection.train_test_split(iris.data, iris.target, train_size=0.80)
pipe = Pipeline([('scaler', StandardScaler()), ('svc', SVC(kernel = 'rbf', C = 10))])
pipe.fit(X_train, Y_train) # It should be Y_train
pipe.score(X_test, Y_test)
I reproduced your error. You wrote pipe.fit(X_train, Y_test)
which is not correct because you must use train features and train labels to train your model. Use test features and labels to make predictions.
Answered By - ForestGump
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.