title: Finding Root Mean Squared Error with Pandas dataframe
body: <p>I am trying to calculate the root mean squared error in from a pandas data frame. I have checked out previous links on stacked overflow such as <a href="https://stackoverflow.com/questions/17197492/root-mean-square-error-in-python">Root mean square error in python</a>
  and  the scikit learn documentation <a href="http://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html" rel="nofollow noreferrer">http://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html</a> I was hoping someone out there would shed some light on what I am doing wrong. 
  Here is the <a href="https://github.com/zaynaib/machineLearningWashington/blob/week1/home_data.csv" rel="nofollow noreferrer">dataset</a>. Here is my code.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  sales = pd.read_csv("home_data.csv")
  
  from sklearn.cross_validation import train_test_split
  train_data,test_data = train_test_split(sales,train_size=0.8)
  
  from sklearn.linear_model import LinearRegression
  X = train_data[['sqft_living']]
  y=train_data.price
  #build the linear regression object
  lm=LinearRegression()
  # Train the model using the training sets
  lm.fit(X,y)
  #print the y intercept
  print(lm.intercept_)
  #print the coefficents
  print(lm.coef_)
  
  lm.predict(300)
  
  
  
  from math import sqrt
  from sklearn.metrics import mean_squared_error
  y_true=train_data.price.loc[0:5,]
  test_data=test_data[['price']].reset_index()
  y_pred=test_data.price.loc[0:5,]
  predicted =y_pred.as_matrix()
  actual= y_true.as_matrix()
  mean_squared_error(actual, predicted)
  </code></pre>
  
  <h1>EDIT</h1>
  
  <p>So this is what worked for me. I had to transform the test dataset values for sqft living from row to column.</p>
  
  <pre><code>from sklearn.linear_model import LinearRegression
  X = train_data[['sqft_living']]
  y=train_data.price
  #build the linear regression object
  lm=LinearRegression()
  # Train the model using the training sets
  lm.fit(X,y)
  </code></pre>
  
  <h1>New code</h1>
  
  <pre><code>test_X = test_data.sqft_living.values
  print(test_X)
  print(np.shape(test_X))
  print(len(test_X))
  test_X = np.reshape(test_X, [4323, 1])
  print(test_X)
  from sklearn.metrics import mean_squared_error
  from sklearn.metrics import explained_variance_score
  MSE = mean_squared_error(y_true = test_data.price.values, y_pred = lm.predict(test_X))
  MSE
  MSE**(0.5)
  </code></pre>