title: ValueError: shapes (399,1) and (2,) not aligned: 1 (dim 1) != 2 (dim 0)
body: <p>I'm trying to build and run a Multiple Regression model using the Communities in the US dataset. However, I'm not sure why I'm getting this error even though the shapes of my X and Y variables are the same.</p>
  <p><strong>My code:</strong></p>
  <pre><code>X1 = crime[&quot;pctWPubAsst&quot;].values
  y1 = crime[&quot;ViolentCrimesPerPop&quot;].values
  
  # Reshaping our variables 
  
  X1 = X1.reshape(-1,1)
  y1 = y1.reshape(-1,1)
  
  X_train, X_test, y_train, y_test = train_test_split(X1, y1, test_size=0.2, random_state=40)
  
  linreg = LinearRegression()
  
  linreg.fit(X_train, y_train)
  
  y_pred = linreg.predict(X_test)
  
  print(&quot;R2: {}&quot;.format(regr.score(X_test, y_test)))
  rmse = np.sqrt(mean_squared_error(y_test, y_pred))
  print(&quot;Root Mean Squared Error: {}&quot;.format(rmse))
  
  plt.scatter(X1, y1)
  plt.plot(X_test, y_pred, color=&quot;black&quot;, linewidth=3)
  plt.show()
  </code></pre>
  <p><strong>The Error I'm getting:</strong></p>
  <pre><code>---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-47-77bd9073c3bd&gt; in &lt;module&gt;
       15 y_pred = linreg.predict(X_test)
       16 
  ---&gt; 17 print(&quot;R2: {}&quot;.format(regr.score(X_test, y_test)))
       18 rmse = np.sqrt(mean_squared_error(y_test, y_pred))
       19 print(&quot;Root Mean Squared Error: {}&quot;.format(rmse))
  
  ~/opt/anaconda3/lib/python3.7/site-packages/sklearn/base.py in score(self, X, y, sample_weight)
      406         from .metrics import r2_score
      407         from .metrics.regression import _check_reg_targets
  --&gt; 408         y_pred = self.predict(X)
      409         # XXX: Remove the check in 0.23
      410         y_type, _, _, _ = _check_reg_targets(y, y_pred, None)
  
  ~/opt/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/base.py in predict(self, X)
      219             Returns predicted values.
      220         &quot;&quot;&quot;
  --&gt; 221         return self._decision_function(X)
      222 
      223     _preprocess_data = staticmethod(_preprocess_data)
  
  ~/opt/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/base.py in _decision_function(self, X)
      204         X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
      205         return safe_sparse_dot(X, self.coef_.T,
  --&gt; 206                                dense_output=True) + self.intercept_
      207 
      208     def predict(self, X):
  
  ~/opt/anaconda3/lib/python3.7/site-packages/sklearn/utils/extmath.py in safe_sparse_dot(a, b, dense_output)
      140         return ret
      141     else:
  --&gt; 142         return np.dot(a, b)
      143 
      144 
  
  &lt;__array_function__ internals&gt; in dot(*args, **kwargs)
  
  ValueError: shapes (399,1) and (2,) not aligned: 1 (dim 1) != 2 (dim 0)
  
  
  </code></pre>
  <p><strong>Shape of my variables</strong></p>
  <p>X_test = (399, 1)
  y_test = (399, 1)</p>
  <p>X_train = (1595, 1)
  y_train = (1595, 1)</p>
  <p>X1 = (1994, 1)
  y1 = (1994, 1)</p>
  <p>Thanks, appreciate the help.</p>