title: TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'numpy.ndarray'
body: <p>I am trying to calculate the Mean Squared Error of the predictions <code>y_train_actual</code> from my sci-kit learn model with the original values <code>salaries</code>.</p>
  
  <p><strong>Problem:</strong> However with <code>mean_squared_error(y_train_actual, salaries)</code>, I am getting the error <code>TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'numpy.ndarray'</code>. Using <code>list(salaries)</code> instead of <code>salaries</code> as the 2nd parameter gives the same error.</p>
  
  <p>With <code>mean_squared_error(y_train_actual, y_valid_actual)</code> I am getting the error <code>Found array with dim 40663. Expected 244768</code></p>
  
  <p>How can I convert to the correct array types for <code>sklearn.netrucs.mean_squared_error()</code>?</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>from sklearn.metrics import mean_squared_error
  
  y_train_actual = [ np.exp(float(row)) for row in y_train ]
  print mean_squared_error(y_train_actual, salaries)
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-144-b6d4557ba9c5&gt; in &lt;module&gt;()
        3 y_valid_actual = [ np.exp(float(row)) for row in y_valid ]
        4 
  ----&gt; 5 print mean_squared_error(y_train_actual, salaries)
        6 print mean_squared_error(y_train_actual, y_valid_actual)
  
  C:\Python27\lib\site-packages\sklearn\metrics\metrics.pyc in mean_squared_error(y_true, y_pred)
     1462     """
     1463     y_true, y_pred = check_arrays(y_true, y_pred)
  -&gt; 1464     return np.mean((y_pred - y_true) ** 2)
     1465 
     1466 
  
  TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'numpy.ndarray'
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code>y_train_actual = [ np.exp(float(row)) for row in y_train ]
  y_valid_actual = [ np.exp(float(row)) for row in y_valid ]
  
  print mean_squared_error(y_train_actual, y_valid_actual)
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>ValueError                                Traceback (most recent call last)
  &lt;ipython-input-146-7fcd0367c6f1&gt; in &lt;module&gt;()
        4 
        5 #print mean_squared_error(y_train_actual, salaries)
  ----&gt; 6 print mean_squared_error(y_train_actual, y_valid_actual)
  
  C:\Python27\lib\site-packages\sklearn\metrics\metrics.pyc in mean_squared_error(y_true, y_pred)
     1461 
     1462     """
  -&gt; 1463     y_true, y_pred = check_arrays(y_true, y_pred)
     1464     return np.mean((y_pred - y_true) ** 2)
     1465 
  
  C:\Python27\lib\site-packages\sklearn\utils\validation.pyc in check_arrays(*arrays, **options)
      191         if size != n_samples:
      192             raise ValueError("Found array with dim %d. Expected %d"
  --&gt; 193                              % (size, n_samples))
      194 
      195         if not allow_lists or hasattr(array, "shape"):
  
  ValueError: Found array with dim 40663. Expected 244768
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code>print type(y_train)
  print type(y_train_actual)
  print type(salaries)
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <pre><code>&lt;type 'list'&gt;
  &lt;type 'list'&gt;
  &lt;type 'tuple'&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>print y_train[:10]</strong></p>
  
  <p><code>[10.126631103850338, 10.308952660644293, 10.308952660644293, 10.221941283654663, 10.126631103850338, 10.126631103850338, 11.225243392518447, 9.9987977323404529, 10.043249494911286, 11.350406535472453]</code></p>
  
  <p><strong>print salaries[:10]</strong></p>
  
  <p><code>('25000', '30000', '30000', '27500', '25000', '25000', '75000', '22000', '23000', '85000')</code></p>
  
  <p><strong>print list(salaries)[:10]</strong></p>
  
  <p><code>['25000', '30000', '30000', '27500', '25000', '25000', '75000', '22000', '23000', '85000']</code></p>
  
  <p><strong>print len(y_train)</strong></p>
  
  <pre><code>244768
  </code></pre>
  
  <p><strong>print len(salaries)</strong></p>
  
  <pre><code>244768
  </code></pre>