I am trying to predict car prices (by machine learning) with a simple linear regression (only one independent variable). The variables are "highway miles per gallon"
0 27
1 27
2 26
3 30
4 22
..
200 28
201 25
202 23
203 27
204 25
Name: highway-mpg, Length: 205, dtype: int64
and "price":
0 13495.0
1 16500.0
2 16500.0
3 13950.0
4 17450.0
...
200 16845.0
201 19045.0
202 21485.0
203 22470.0
204 22625.0
Name: price, Length: 205, dtype: float64
With the following code:
from sklearn.linear_model import LinearRegression
x = df["highway-mpg"]
y = df["price"]
lm = LinearRegression()
lm.fit([x],[y])
Yhat = lm.predict([x])
print(Yhat)
print(lm.intercept_)
print(lm.coef_)
However, the intercept and slope coefficient print commands give me the following output:
[[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
...
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]]
Why doesn't it print the intercept and slope coefficient? The "Yhat" print command does print out the predicted values in an array properly, but somehow the other print commands do not print my desired output...