title: 10-fold cross-validation and obtaining RMSE
body: <p>I'm trying to compare the RMSE I have from performing multiple linear regression upon the full data set, to that of 10-fold cross validation, using the KFold module in scikit learn.  I found some code that I tried to adapt but I can't get it to work (and I suspect it never worked in the first place.</p>
  
  <p>TIA for any help!</p>
  
  <h2>Here's my linear regression function</h2>
  
  <pre><code>  def standRegres(xArr,yArr):
        xMat = np.mat(xArr); yMat = np.mat(yArr).T
        xTx = xMat.T*xMat
        if np.linalg.det(xTx) == 0.0:
            print("This matrix is singular, cannot do inverse")
            return
        ws = xTx.I * (xMat.T*yMat)
        return ws
  
    ##  I run it on my matrix ("comm_df") and my dependent var (comm_target)
  
    ##  Calculate RMSE (omitted some code)
  
    initial_regress_RMSE = np.sqrt(np.mean((yHat_array - comm_target_array)**2)
  
    ##  Now trying to get RMSE after training model through 10-fold cross validation
  
    from sklearn.model_selection import KFold
    from sklearn.linear_model import LinearRegression
  
    kf = KFold(n_splits=10)
    xval_err = 0
    for train, test in kf:
        linreg.fit(comm_df,comm_target)
        p = linreg.predict(comm_df)
        e = p-comm_target
        xval_err += np.sqrt(np.dot(e,e)/len(comm_df))
  
    rmse_10cv = xval_err/10
  </code></pre>
  
  <p>I get an error about how kfold object is not iterable</p>