Last answered:

31 Jul 2020

Posted on:

30 Jul 2020

0

ValueError

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 answers ( 0 marked as helpful)
Instructor
Posted on:

31 Jul 2020

0
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

Submit an answer