The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

ValueError

ValueError

0
Votes
1
Answer
ValueError                                Traceback (most recent call last)
<ipython-input-12-c1c06f334644> in <module>
----> 1 reg.predict(3200)

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\linear_model\base.py in predict(self, X)
    219             Returns predicted values.
    220         """
--> 221         return self._decision_function(X)
    222 
    223     _preprocess_data = staticmethod(_preprocess_data)

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\linear_model\base.py in _decision_function(self, X)
    202         check_is_fitted(self, "coef_")
    203 
--> 204         X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
    205         return safe_sparse_dot(X, self.coef_.T,
    206                                dense_output=True) + self.intercept_

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
    512                     "Reshape your data either using array.reshape(-1, 1) if "
    513                     "your data has a single feature or array.reshape(1, -1) "
--> 514                     "if it contains a single sample.".format(array))
    515             # If input is 1D raise error
    516             if array.ndim == 1:

ValueError: Expected 2D array, got scalar array instead:
array=3200.
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
1 Answer

365 Team
0
Votes

Hi there,
Well, the function is expecting a 2D array. 
Therefore, to achieve the desired result, please write: reg.predict([[3200]]).
Best,
The 365 Team