title: scikit-learn: How to calculate root-mean-square error (RMSE) in percentage?
body: <p>I have a dataset (found in this link: <a href="https://drive.google.com/open?id=0B2Iv8dfU4fTUY2ltNGVkMG05V00" rel="nofollow noreferrer">https://drive.google.com/open?id=0B2Iv8dfU4fTUY2ltNGVkMG05V00</a>) of the following format. </p>
  
  <pre><code> time     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
    ...
  9.987735  55 239
  9.987739  56 239
  9.987744  57 239
  9.987749  58 239
  9.987938  59 239
  </code></pre>
  
  <p>The third column (Y) in my dataset is my true value - that's what I wanted to predict (estimate). I want to do a prediction of <code>Y</code> (i.e. predict the current value of <code>Y</code> according to the previous 100 rolling values of <code>X</code>. For this, I have the following <code>python</code> script work using <code>random forest regression model</code>.</p>
  
  <pre><code>#!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  """
  
  @author: deshag
  """
  
  import pandas as pd
  import numpy as np
  from io import StringIO
  from sklearn.ensemble import RandomForestRegressor
  from sklearn.metrics import mean_squared_error
  from math import sqrt
  
  
  
  df = pd.read_csv('estimated_pred.csv')
  
  for i in range(1,100):
      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(100)}).apply(np.nan_to_num, axis=0).values
  
  
  y = df['Y'].values
  
  
  reg = RandomForestRegressor(criterion='mse')
  reg.fit(X,y)
  modelPred = reg.predict(X)
  print(modelPred)
  
  print("Number of predictions:",len(modelPred))
  
  meanSquaredError=mean_squared_error(y, modelPred)
  print("MSE:", meanSquaredError)
  rootMeanSquaredError = sqrt(meanSquaredError)
  print("RMSE:", rootMeanSquaredError)
  </code></pre>
  
  <p>At the end, I measured the root-mean-square error (RMSE) and got an <code>RMSE</code> of <code>19.57</code>. From what I have read from the documentation, it says that squared errors have the same units as of the response. Is there any way to present the value of an <code>RMSE</code> in percentage? For example, to say this percent of the prediction is correct and this much wrong.</p>
  
  <p>There is a <code>check_array</code> function for calculating <code>mean absolute percentage error (MAPE)</code>  in the recent version of <code>sklearn</code> but it doesn't seem to work the same way as the previous version when i try it as in the following.</p>
  
  <pre><code>import numpy as np
  from sklearn.utils import check_array
  
  def calculate_mape(y_true, y_pred): 
  y_true, y_pred = check_array(y_true, y_pred)
  
      return np.mean(np.abs((y_true - y_pred) / y_true)) * 100
  
  calculate_mape(y, modelPred)
  </code></pre>
  
  <p>This is returning an error: <code>ValueError: not enough values to unpack (expected 2, got 1)</code>. And this seems to be that the <code>check_array</code> function in the recent version returns only a <a href="http://scikit-learn.org/dev/modules/generated/sklearn.utils.check_array.html" rel="nofollow noreferrer">single value</a>, unlike the previous version. </p>
  
  <p>Is there any way to present the <code>RMSE</code> in percentage or calculate <code>MAPE</code> using <code>sklearn</code> for <code>Python</code>?</p>