title: Python: 'for' loops and iteration in Linear Regression
body: <p>I'm building a basic Linear regression model using the <code>statsmodel</code> package and here's what I'm trying to do:<br>
  Build a 'for' loop that checks the probabilities of each of the features, checks if they're greater than 0.05, if yes: drop the feature from training (&amp; test) data, fit model again, and repeat till all probabilities are &lt; 0.05.<br>
  Here's what I've done so far:   </p>
  
  <pre><code>for x,y in zip(lrmodel.pvalues,xtrain.columns): 
     if x&gt;0.05:
        xtrain = xtrain.drop(y,axis=1)
        xtest = xtest.drop(y,axis=1)
        lrmodel = sm.OLS(ytrain,xtrain).fit()
        finalmodel = lrmodel
      else:
        finalmodel = lrmodel
  </code></pre>
  
  <p>The problem with this loop is that it doesn't iterate over the pvalues, rather it removes all the probabilities>0.05 within a single shot.<br>
  If anyone could help me, I would be grateful. Thanks!</p>