Printing coeficients of several linear regressions on a single python script
<p>I am running this code:</p>

<pre><code>import sklearn
IVS=['CRIM', 'RM', 'PTRATIO']
IVS2=['CRIM','PTRATIO']
model1=lm.fit(bos[IVS],bos.PRICE)
model2=lm.fit(bos[IVS2],bos.PRICE)

print(model1.coef_)
print(model2.coef_)
</code></pre>

<p>When trying to print out the coefficients for both models, I only get the last model coef for both print functions:</p>

<pre><code>[-0.27939868 -1.83737204]
[-0.27939868 -1.83737204]
</code></pre>

<p>Any idea why this is?</p>

<p>You need to create separate instances of your classifier before you call fit:</p>

<pre><code>from sklearn.linear_model import LinearRegression()
model1 = LinearRegression()
model1.fit(bos[IVS],bos.PRICE)
model2 = LinearRegression()
model2.fit(bos[IVS2],bos.PRICE)
</code></pre>

python scikit-learn regression linear coefficients