Implementing linear regression as below:
from sklearn.linear_model import LinearRegression
x = [1,2,3,4,5,6,7]
y = [1,2,1,3,2.5,2,5]
# Create linear regression object
regr = LinearRegression()
# Train the model using the training sets
regr.fit([x], [y])
# print(x)
regr.predict([[1, 2000, 3, 4, 5, 26, 7]])
produces :
array([[1. , 2. , 1. , 3. , 2.5, 2. , 5. ]])
In utilizing the predict function why cannot utilize a single x value in order to make prediction?
Trying regr.predict([[2000]])
returns:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-3a8b477f5103> in <module>()
11
12 # print(x)
---> 13 regr.predict([[2000]])
/usr/local/lib/python3.6/dist-packages/sklearn/linear_model/base.py in predict(self, X)
254 Returns predicted values.
255 """
--> 256 return self._decision_function(X)
257
258 _preprocess_data = staticmethod(_preprocess_data)
/usr/local/lib/python3.6/dist-packages/sklearn/linear_model/base.py in _decision_function(self, X)
239 X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
240 return safe_sparse_dot(X, self.coef_.T,
--> 241 dense_output=True) + self.intercept_
242
243 def predict(self, X):
/usr/local/lib/python3.6/dist-packages/sklearn/utils/extmath.py in safe_sparse_dot(a, b, dense_output)
138 return ret
139 else:
--> 140 return np.dot(a, b)
141
142
ValueError: shapes (1,1) and (7,7) not aligned: 1 (dim 1) != 7 (dim 0)