title: Print predict ValueError: Expected 2D array, got 1D array instead
body: <p>The error shows in my last two codes.</p>
  
  <blockquote>
    <p>ValueError: Expected 2D array, got 1D array instead: array=[0 1].</p>
  </blockquote>
  
  <p><br></p>
  
  <blockquote>
    <p>Reshape your data either using array.reshape(-1, 1) if your data has a
    single feature or array.reshape(1, -1) if it contains a single sample.</p>
  </blockquote>
  
  <pre><code>import numpy as np
  
  import pandas as pd
  
  from sklearn.model_selection import ShuffleSplit
  
  %matplotlib inline
  
  df = pd.read_csv('.......csv')
  df.drop(['Company'], 1, inplace=True)
  
  x = pd.DataFrame(df.drop(['R&amp;D Expense'],1))
  y = pd.DataFrame(df['R&amp;D Expense'])
  
  X_test = x.index[[0,1]]
  y_test = y.index[[0,1]]
  
  X_train = x.drop(x.index[[0,1]])
  y_train = y.drop(y.index[[0,1]])
  
  from sklearn.metrics import r2_score
  def performance_metric(y_true, y_predict):
      score = r2_score(y_true, y_predict)
      return score
  
  from sklearn.metrics import make_scorer
  from sklearn.neighbors import KNeighborsRegressor
  from sklearn.model_selection import GridSearchCV
  
  def fit_model_shuffle(x, y):
  
    cv_sets = ShuffleSplit(n_splits = 10, test_size = 0.20, random_state = 0)
  
    regressor = KNeighborsRegressor()
      params = {'n_neighbors':range(3,10)}
  
         scoring_fnc = make_scorer(performance_metric)
       grid = GridSearchCV(regressor, param_grid=params,scoring=scoring_fnc,cv=cv_sets)
      grid = grid.fit(x, y)
      return grid.best_estimator_
  
  reg = fit_model_shuffle(X_train, y_train)
  
  &gt; for i, y_predict in enumerate(reg.predict(X_test),1):
      print(i, y_predict)
  </code></pre>