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

Updated plotting function! #883

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Updated plotting function! #883

wants to merge 2 commits into from

Conversation

ivanvajs1996
Copy link
Collaborator

The plotting function has been updated with the linear fit line and the R2 residual display.

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 15.38462% with 11 lines in your changes missing coverage. Please review.

Project coverage is 35.96%. Comparing base (67a458e) to head (2ccfba6).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/pymovements/plotting/main_sequence_plot.py 15.38% 11 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              main     #883       +/-   ##
============================================
- Coverage   100.00%   35.96%   -64.04%     
============================================
  Files           74       69        -5     
  Lines         3372     3259      -113     
  Branches       594      567       -27     
============================================
- Hits          3372     1172     -2200     
- Misses           0     2082     +2082     
- Partials         0        5        +5     

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

Copy link
Contributor

@dkrako dkrako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks a lot! I have just some minor change requests, mostly relating to the function signature.

The plot testing is currently very rudimentary in pymovements. You don't need to check the plots for correctness, but you'll need to cover all branches such that we at least test that there's no unexpected runtime errors.

import polars as pl
from matplotlib.collections import Collection
from sklearn.metrics import r2_score

from pymovements.events import EventDataFrame


def main_sequence_plot(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add one argument for turning the fit and the R2 on and off.

something like this:

fit: bool = True,
measure: bool = True,

Although we could also call it line, we should keep in mind that we might want to do non-linear fits somewhen.
Having the more general name would enable us to use the argument to specify the method in the future like fit='linear' or fit='exponential', where fit=True would be equivalent to fit='linear'.

The same holds true for the R2 measure. In contrast to what I said yesterday, R2 is not a valid measure for nonlinear fits, so here too, we could specify measures in the future, e.g. standard error of regression S.

These two blog posts are probably good inspiration for making this PR future proof for follow ups:
https://blog.minitab.com/en/adventures-in-statistics-2/why-is-there-no-r-squared-for-nonlinear-regression
https://blog.minitab.com/en/adventures-in-statistics-2/regression-analysis-how-to-interpret-s-the-standard-error-of-the-regression

marker_size: float = 25,
color: str = 'purple',
color_line: str = 'red',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's call the argument fit_color

alpha: float = 0.5,
marker: str = 'o',
figsize: tuple[int, int] = (15, 5),
title: str | None = None,
savepath: str | None = None,
title: str = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert these two changes to allow for None

line_x = [min_ampl, max_ampl]
line_y = [a * min_ampl + b, a * max_ampl + b]

# residual calcualtion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

import polars as pl
from matplotlib.collections import Collection
from sklearn.metrics import r2_score
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to add sklearn to the dependencies in https://github.com/aeye-lab/pymovements/blob/main/pyproject.toml

@dkrako dkrako linked an issue Oct 25, 2024 that may be closed by this pull request
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.

Plotting the main sequence fit and R2
2 participants