I am trying to fit this data using linear regression following the bigdataexaminer guide. Up to this point, everything worked fine. I imported LinearRegression from sklearn and printed the number of odds just fine. This was the code before I tried to grab the odds from the console.
import numpy as np
import pandas as pd
import scipy.stats as stats
import matplotlib.pyplot as plt
import sklearn
from sklearn.datasets import load_boston
from sklearn.linear_model import LinearRegression
boston = load_boston()
bos = pd.DataFrame(boston.data)
bos.columns = boston.feature_names
bos['PRICE'] = boston.target
X = bos.drop('PRICE', axis = 1)
lm = LinearRegression()
After I installed all this, I ran the following command and returned the correct output:
In [68]: print('Number of coefficients:', len(lm.coef_)
Number of coefficients: 13
However, if I ever try to print the same line again or use 'lm.coef_', it tells me that coef_ is not an attribute of LinearRegression, right after I SIMPLY used it successfully, and I didnโt do that, touch any from the code before I try it again.
In [70]: print('Number of coefficients:', len(lm.coef_))
Traceback (most recent call last):
File "<ipython-input-70-5ad192630df3>", line 1, in <module>
print('Number of coefficients:', len(lm.coef_))
AttributeError: 'LinearRegression' object has no attribute 'coef_'