AttributeError: LinearRegression object has no attribute 'coef_'
<p>I've been attempting to fit this data by a Linear Regression, following a tutorial on bigdataexaminer. Everything was working fine up until this point. I imported LinearRegression from sklearn, and printed the number of coefficients just fine. This was the code before I attempted to grab the coefficients from the console.</p>

<pre><code>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()
</code></pre>

<p>After I had all this set up I ran the following command, and it returned the proper output:</p>

<pre><code>In [68]: print('Number of coefficients:', len(lm.coef_)

Number of coefficients: 13
</code></pre>

<p>However, now if I ever try to print this same line again, or use 'lm.coef_', it tells me coef_ isn't an attribute of LinearRegression, right after I JUST used it successfully, and I didn't touch any of the code before I tried it again.</p>

<pre><code>In [70]: print('Number of coefficients:', len(lm.coef_))

Traceback (most recent call last):

 File "&lt;ipython-input-70-5ad192630df3&gt;", line 1, in &lt;module&gt;
print('Number of coefficients:', len(lm.coef_))

AttributeError: 'LinearRegression' object has no attribute 'coef_'
</code></pre>