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

Improve regression example #2405

Merged
merged 6 commits into from
Oct 24, 2024
Merged

Improve regression example #2405

merged 6 commits into from
Oct 24, 2024

Conversation

laggui
Copy link
Member

@laggui laggui commented Oct 22, 2024

Pull Request Template

Checklist

  • Confirmed that run-checks all script has been executed.
  • Made sure the book is up to date with changes in this PR.

Related Issues/PRs

Fixes #2401

Changes

The previous example had some issues regarding input and feature normalization, and the model did not converge well.

I have adapted the simple regression example to use a more simple dataset (in terms of features and target variable): the California housing dataset.

The model remains pretty much the same, but I changed some minor details for the training config.

I've also added the code for inference and display a nice little graph for 1000 samples (predicted vs expected). The console looks like this (minus the colorized points) when the example completes:

Train Dataset Size: 16640
Valid Dataset Size: 2000
======================== Learner Summary ========================
Model:
RegressionModel {
  input_layer: Linear {d_input: 8, d_output: 64, bias: true, params: 576}
  output_layer: Linear {d_input: 64, d_output: 1, bias: true, params: 65}
  activation: Relu
  params: 641
}
Total Epochs: 100


| Split | Metric | Min.     | Epoch    | Max.     | Epoch    |
|-------|--------|----------|----------|----------|----------|
| Train | Loss   | 0.435    | 100      | 3.481    | 1        |
| Valid | Loss   | 0.589    | 51       | 5.093    | 1        |

Predicted vs. Expected Median House Value (in 100,000$)
⡁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 5.0
⠄⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⡁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠔⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠄⢀⠈⠀⠁⠠⡀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⡀⢀⢀⡁⡀⠐⢤⠀⠀⣊⠐⠸⡉⢄⠀⠐⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⡁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠄⡀⠀⠀⠀⠀⠀⠀⠀⣂⠐⠒⠾⠂⠈⠙⡐⠒⡐⠎⠂⠐⠀⠀⠐⠐⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⠉⠂⠀⠢⡂⢁⠤⡆⢪⣼⡳⡾⢧⢂⡄⠿⠇⠈⠀⠀⠀⠐⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠀⠀⠀⢄⠅⠌⠀⡀⡡⡂⡦⡹⠮⡮⣫⡵⢐⠈⡃⠔⠚⠀⠠⠘⠀⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⡁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⡀⢂⣧⢃⢂⡚⣃⢲⣖⢞⡧⣶⣚⡽⡫⢮⣳⣟⠅⡉⠀⠀⠈⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⡄⠀⠀⠀⠀⠀⠀⠀⡀⢀⠀⢧⣸⣂⣹⠻⣽⣺⣯⣻⣿⣣⢯⣿⣟⡖⡉⡴⠄⢄⠄⢀⠀⠀⠁⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠂⠀⠀⠀⠀⠀⡀⣨⢧⢊⡸⡺⣴⣟⣞⡿⣽⣙⣽⡷⣣⢷⡽⠣⢊⡂⠈⡂⠀⠁⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⡁⠀⠀⢼⠆⣮⣧⣵⢝⣽⡿⡿⣿⣳⡫⡏⠛⠋⠇⡟⠛⠈⣇⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⡤⠆⠟⠛⠛⠽⠊⠛⠙⠟⠉⠓⠈⠁⠈⠀⠀⠐⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠂⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁⠈⠀⠁ 0.0
0.0                                                      5.0

Predicted 2.1703506 Expected 2.158

Testing

Tested the example with all feature flags.

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.25%. Comparing base (80c831b) to head (2385e91).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2405      +/-   ##
==========================================
- Coverage   85.26%   85.25%   -0.01%     
==========================================
  Files         792      792              
  Lines      104516   104552      +36     
==========================================
+ Hits        89115    89140      +25     
- Misses      15401    15412      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nathanielsimard nathanielsimard merged commit 09c65ca into main Oct 24, 2024
11 checks passed
@nathanielsimard nathanielsimard deleted the examples/rework/regression branch October 24, 2024 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All inferences have the same predicted value
2 participants