I am implementing simple linear regression and multiple linear regression using pandas and sklearn
My code is as follows
import pandas as pd
import numpy as np
import scipy.stats
from sklearn import linear_model
from sklearn.metrics import r2_score
df = pd.read_csv("Auto.csv", na_values='?').dropna()
lr = linear_model.LinearRegression()
y = df['mpg']
x = df['displacement']
X = x.values.reshape(-1,1)
sklearn_model = lr.fit(X,y)
This works fine, but for multiple linear regression, for some reason it doesn't work WITH the () at the end of sklearn's linear regression, when I use it with the brackets I get the following error:
TypeError: 'LinearRegression' object is not callable
My multiple linear regression code is as follows:
lr = linear_model.LinearRegression
feature_1 = np.array(df[['displacement']])
feature_2 = np.array(df[['weight']])
feature_1 = feature_1.reshape(len(feature_1),1)
feature_2 = feature_2.reshape(len(feature_2),1)
X = np.hstack([feature_1,feature_2])
sklearn_mlr = lr(X,df['mpg'])
I want to know what I'm doing wrong. Additionally, I'm not able to print the various attributes in the linear regression method if I don't use the () at the end. e.g.
print(sklearn_mlr.coef_)
Gives me the error:
AttributeError: 'LinearRegression' object has no attribute 'coef_'