GokuMohandas / Made-With-ML

Learn how to design, develop, deploy and iterate on production-grade ML applications.
https://madewithml.com
MIT License
37.1k stars 5.88k forks source link

Foundations --> Linear regression (Error in implementation) #198

Closed gitgithan closed 2 years ago

gitgithan commented 2 years ago

Under Pytorch --> Interpretability: b_unscaled = b * y_scaler.scale_ + y_scaler.mean_ - np.sum(W_unscaled*X_scaler.mean_) This line seems to be missing a * (y_scaler.scale_/X_scaler.scale_) in the last np.sum term.

The table for W unscaled was also confusing. It has a sum term shown there, which means if X began with 2 predictors (this lesson only used 1 predictor), the scaled W will have 2 predictors while the sum will aggregate the 2 weights into 1 unscaled weight? Can't wrap my head around this.

Also, under Pytorch --> Interpretability, W_unscaled = W * (y_scaler.scale_/X_scaler.scale_) there was no sum used here, so looks inconsistent with the formula in the table.

image

GokuMohandas commented 2 years ago

hey @gitgithan ,

So I could have represented b_unscaled this way:

But because the expression W * (y_std/X_std) = W_unscaled, I just substituted it into the b_unscaled equation.

And hmm good point, the summation notation doesn't belong here if we're trying to find the value of each W_j so it should be removed. Which now matches with the way we write in code for this scenario.

Hope you're enjoying the lessons @gitgithan and definitely keep the feedback coming! I'll incorporate these changes when I have some time later this month.

gitgithan commented 2 years ago

Ah sorry i was careless, didn't see that substitution because my 1st reaction was why doesn't the code look like the math latex. What about smaller feedback (eg. typos?) I must have seen quite a few up to this point but thought you may not want to bother.

GokuMohandas commented 2 years ago

yeah I'm planning to clean all of this up and adding a lot more when I have some time this winter break. Definitely let me know if there are major conceptual mistakes but typos will be fixed later this year.

Also let me know if something doesn't make sense because it helps make the content clearer for others. For example, I'll be adding one more step before the substitution so it becomes clearer in the scenario above.