ddbourgin / numpy-ml

Machine learning, in numpy
https://numpy-ml.readthedocs.io/
GNU General Public License v3.0
15.26k stars 3.7k forks source link

`numpy_ml.linear_model.LinearRegression.predict()` generates `ValueError` when used with copy-pasted code, but pip installed version works as expected!! #77

Open naveen-marthala opened 2 years ago

naveen-marthala commented 2 years ago

System information

Describe the current behavior I have copy-pasted the code for numpy_ml.linear_model.LinearRegression from github and did .fit() and .predict() on some dummy data. I got ValueError on .predict() like this:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-10-4be896198177>](https://localhost:8080/#) in <module>()
----> 1 npml_lin_reg2_preds = npml_lin_reg2.predict(X_val)
      2 npml_lin_reg2_preds[:10]

[<ipython-input-8-fc521849e158>](https://localhost:8080/#) in predict(self, X)
    206         if self.fit_intercept:
    207             X = np.c_[np.ones(X.shape[0]), X]
--> 208         return X @ self.beta

ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 11)

Describe the expected behavior Expected behaviour is that .predict() doesn't generate ValueError.

Code to reproduce the issue not code, here is the link to the notebook: https://colab.research.google.com/drive/12q9r2j4-UpUrPnzvMiPC6rxafa73cY5L?usp=sharing

Other info / logs

ddbourgin commented 2 years ago

Thanks for raising this + the comprehensive Colab notebook - I appreciate it! Yup, you're right, it looks like the "updated" version in the repo is returning the beta transpose rather than beta, so there's a dimension mismatch during prediction.

I'll try to push a fix for this shortly. Thanks for the heads up :)