Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Mar 20, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@naveen-marthala
Copy link

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 18.04
  • Python version: 3.7.12
  • NumPy version: 1.21.5
    (environment is Google Colab on 20-Mar, 2022.)

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 ddbourgin added the bug Something isn't working label Mar 20, 2022
@ddbourgin
Copy link
Owner

ddbourgin commented Mar 20, 2022

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants