ValueError: X has 23 features per sample; expecting 16

predic=logreg.predict(x_test)

ValueError Traceback (most recent call last)
in
----> 1 predic=logreg.predict(x_test)

~\Anaconda3\lib\site-packages\sklearn\linear_model\base.py in predict(self, X)
287 Predicted class label per sample.
288 “”"
–> 289 scores = self.decision_function(X)
290 if len(scores.shape) == 1:
291 indices = (scores > 0).astype(np.int)

~\Anaconda3\lib\site-packages\sklearn\linear_model\base.py in decision_function(self, X)
268 if X.shape[1] != n_features:
269 raise ValueError(“X has %d features per sample; expecting %d”
–> 270 % (X.shape[1], n_features))
271
272 scores = safe_sparse_dot(X, self.coef_.T,

ValueError: X has 23 features per sample; expecting 16

Hi @sarika77, could you please share the shape of your x_train and x_test dataframes?

Do u want the code ??
Who are you ?

Hi @sarika77, I am one of the moderators for the platform. Regarding the error you have shared, looks like the shape (specifically number of features) for the training and test data are different.

If you could share the size of both the dataframes, I would be able to understand the problem better.

© Copyright 2013-2019 Analytics Vidhya