0

Considering this thread, I can not yet get the reason how to know the model expects the input must be in a format.

According to the error message, you have input data in the format [45000, 50000, 60000, ...]. But the model expects the input in the format like [[45000], [50000], [60000], ...] - a list of the lists. So reshape(-1, 1) just changes a format.

Why y not to be as 2Darray? Why just X must be?

GoodDeeds
  • 7,956
  • 5
  • 34
  • 61
john
  • 27
  • 6
  • 1
    In general, a scikit-learn model will expect `X` to be of shape `(n_samples, n_features)` or, if you only have one feature, `(n_samples,)`. – Camilo Martinez M. Apr 28 '21 at 20:16

1 Answers1

0

From the documentation of sklearn.svm.SVC, for the predict method:

Parameters

X: {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples_test, n_samples_train)

For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).

So, even when you have exactly one value X for which you want the prediction, your input shape needs to be (1, n_features), since you have nsamples equal to 1, instead of (n_features), which is not supported.

GoodDeeds
  • 7,956
  • 5
  • 34
  • 61