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

Closed
opened 2025-11-02 00:01:46 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @gitgithan on GitHub (Oct 12, 2021).

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

Originally created by @gitgithan on GitHub (Oct 12, 2021). 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](https://user-images.githubusercontent.com/29853829/136892649-a52c55e8-04ad-43b7-b38a-3a544e87e459.png)
Author
Owner

@GokuMohandas commented on GitHub (Oct 12, 2021):

hey @gitgithan ,

So I could have represented b_unscaled this way:

  • W_unscaled = W * (y_std/X_std)
  • b_unscaled = b * y_std + y_mean - np.sum(W * (y_std/X_std) * X_mean)

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

  • b_unscaled = b * y_std + y_mean - np.sum(W_unscaled*X_mean)

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.

@GokuMohandas commented on GitHub (Oct 12, 2021): hey @gitgithan , So I could have represented `b_unscaled` this way: - `W_unscaled` = `W` * (`y_std`/`X_std`) - `b_unscaled` = `b` * `y_std `+ `y_mean` - np.sum(`W` * (`y_std`/`X_std`) * `X_mean`) But because the expression `W` * (`y_std`/`X_std`) = `W_unscaled`, I just substituted it into the `b_unscaled` equation. - `b_unscaled` = `b` * `y_std` + `y_mean` - np.sum(`W_unscaled`*`X_mean`) 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.
Author
Owner

@gitgithan commented on GitHub (Oct 12, 2021):

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.

@gitgithan commented on GitHub (Oct 12, 2021): 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.
Author
Owner

@GokuMohandas commented on GitHub (Oct 12, 2021):

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.

@GokuMohandas commented on GitHub (Oct 12, 2021): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/Made-With-ML#27