title: Python: How can we match values of predicted and truth values of a regression model
body: <p>We are trying to plot the predicted values and truth values on the same graph after fitting a model to predict a truth value using a <code>RandomForestRegressor</code> in <code>Python</code> of the <a href="https://drive.google.com/open?id=0B4Ajk8jGD1OxSEl2cnF6TC1lUXM" rel="nofollow noreferrer">three column dataset</a> (click the link to download the full <code>CSV</code>-dataset formatted as in the following</p>
  
  <pre><code>t_stamp,X,Y
  0.000543,0,10
  0.000575,0,10
  0.041324,1,10
  0.041331,2,10
  0.041336,3,10
  0.04134,4,10
  0.041345,5,10
  0.04135,6,10
  0.041354,7,10
  </code></pre>
  
  <p>Here is how we do the prediction. </p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import glob, os
  from io import StringIO
  from sklearn.ensemble import RandomForestRegressor
  from sklearn.metrics import mean_squared_error
  from sklearn.metrics import accuracy_score
  import math
  from math import sqrt
  from sklearn.cross_validation import train_test_split
  
  df = pd.concat(map(pd.read_csv, glob.glob(os.path.join('', "data*.csv"))))
  
  for i in range(1,10):
      df['X_t'+str(i)] = df['X'].shift(i)
  
  print(df)
  
  df.dropna(inplace=True)
  
  X = pd.DataFrame({ 'X_%d'%i : df['X'].shift(i) for i in range(10)}).apply(np.nan_to_num, axis=0).values
  y = df['Y'].values
  
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.40)
  
  
  reg = RandomForestRegressor(criterion='mse')
  reg.fit(X_train,y_train)
  
  
  modelPred_test = reg.predict(X_test)
  
  print(modelPred_test)
  </code></pre>
  
  <p>For comparison, we wish to generate a plot before prediction and after prediction. For the truth value, we tried it with</p>
  
  <pre><code>fig, ax = plt.subplots()
  ax.plot(df['time'].values, df['Y'].values)
  </code></pre>
  
  <p>We wish to plot (in the same graph) the ground truth (<code>time</code> as x-axis and the value of <code>Y</code> as y-axis. When we do </p>
  
  <pre><code>ax.plot(df['time'].values, modelPred_test)
  </code></pre>
  
  <p>We are getting the following error.</p>
  
  <pre><code>    raise ValueError("x and y must have same first dimension")
  
  ValueError: x and y must have same first dimension
  </code></pre>
  
  <p>This means that we have less prediction values than we have time stamps in our dataset. To verify this, I did
  <code>print(df['time'].values.shape)</code> and <code>print(modelPred_test.shape)</code> - and it outputs <code>(258523,)</code> and <code>(103410,)</code> respectively. How can we match which of my time values correspond to the prediction values, then i can use a subset of the time values for my plot command?</p>