title: How to fix "IndexError: tuple index out of range" in python?
body: <p>I am using <code>sklearn</code> modules to find the best fitting models and model parameters. However, I have an unexpected Index error down below:</p>
  
  <pre><code>&gt; IndexError                                Traceback (most recent call
  &gt; last) &lt;ipython-input-38-ea3f99e30226&gt; in &lt;module&gt;
  &gt;      22             s = mean_squared_error(y[ts], best_m.predict(X[ts]))
  &gt;      23             cv[i].append(s)
  &gt; ---&gt; 24     print(np.mean(cv, 1))
  &gt; IndexError: tuple index out of range
  </code></pre>
  
  <p>what I want to do is to find best fitting regressor and its parameters, but I got above error. I looked into <code>SO</code> and tried <a href="https://stackoverflow.com/questions/20296188/indexerror-tuple-index-out-of-range-python">this solution</a> but still, same error bumps up. any idea to fix this bug? can anyone point me out why this error happening? any thought?</p>
  
  <p><strong>my code</strong>:</p>
  
  <pre><code>from sklearn.model_selection import KFold
  from sklearn.metrics import mean_squared_error
  from sklearn.linear_model import LinearRegression, Ridge, Lasso
  from xgboost.sklearn import XGBRegressor
  
  from sklearn.datasets import make_regression
  
  models = [SVR(), RandomForestRegressor(), LinearRegression(), Ridge(), Lasso(), XGBRegressor()]
  params = [{'C': [0.01, 1]}, {'n_estimators': [10, 20]}]
  
  X, y = make_regression(n_samples=10000, n_features=20)
  
  with warnings.catch_warnings():
      warnings.filterwarnings("ignore")
      cv = [[] for _ in range(len(models))]
      fold = KFold(5,shuffle=False)
      for tr, ts in fold.split(X):
          for i, (model, param) in enumerate(zip(models, params)):
              best_m = GridSearchCV(model, param)
              best_m.fit(X[tr], y[tr])
              s = mean_squared_error(y[ts], best_m.predict(X[ts]))
              cv[i].append(s)
      print(np.mean(cv, 1))
  </code></pre>
  
  <p><strong>desired output</strong>:</p>
  
  <p>if there is a way to fix up above error, I am expecting to pick up best-fitted models with parameters, then use it for estimation. Any idea to improve the above attempt? Thanks</p>