title: different results regression directly vs a generic sklearn function
body: <p>I am getting different results when I do a simple linear regression directly vs a function that can accept any modelling parameters and do cross-validation. That seems to be the only difference to me but why are the results so different.</p>
  
  <h3>Using linear_model.LinearRegression() directly</h3>
  
  <pre><code>x_train,x_test,y_train,y_test = train_test_split(features.values,target.values)
  regr = linear_model.LinearRegression()
  regr.fit(x_train, y_train)
  print(np.mean((regr.predict(x_test) - y_test) ** 2))
  </code></pre>
  
  <h3>Results:</h3>
  
  <pre><code>395.68
  </code></pre>
  
  <h3>Using generic function</h3>
  
  <pre><code>from sklearn.model_selection import KFold
  from scipy.sparse import csr_matrix
  from sklearn.metrics import r2_score
  
  def cv_predict_report(func,params,features,target,fold,verbose=False):
      model_details,rmse = [],[]
      kf = KFold(n_splits=fold)
  
      for train_ix, test_ix in kf.split(features):
  
          x_train_poly, x_test_poly = features.iloc[train_ix].values,features.iloc[test_ix].values
          y_train,y_test = target.iloc[train_ix],target.iloc[test_ix]
  
          #model
          model = func(**params)
          model.fit(csr_matrix(x_train_poly),y_train)
  
          #save model details
          model_details.append(model)
  
          #predictions
          preds = model.predict(x_test_poly)
  
          model_rmse = np.mean((preds - y_test) ** 2)
          rmse.append(model_rmse)
  
      return model_details,rmse
  </code></pre>
  
  <h3>Call function with linear_model.LinearRegression</h3>
  
  <pre><code>from sklearn import linear_model
  lm_model,lm_rmse = cv_predict_report(linear_model.LinearRegression,{},features,target,fold = 2)
  print(lm_rmse)
  </code></pre>
  
  <h3>Results</h3>
  
  <pre><code>[440.2067193330667, 437.6263639733618]
  </code></pre>