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

Feature/fpca_regression #466

Merged
merged 51 commits into from
Mar 1, 2023
Merged

Feature/fpca_regression #466

merged 51 commits into from
Mar 1, 2023

Conversation

Ddelval
Copy link
Contributor

@Ddelval Ddelval commented Aug 7, 2022

Add the FPCA regression estimator

@Ddelval Ddelval requested a review from vnmabus August 7, 2022 19:21
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 7, 2022

Codecov Report

Patch coverage: 99.01% and project coverage change: +0.11 🎉

Comparison is base (48d1fae) 85.51% compared to head (5ab79ca) 85.63%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #466      +/-   ##
===========================================
+ Coverage    85.51%   85.63%   +0.11%     
===========================================
  Files          141      143       +2     
  Lines        11284    11384     +100     
===========================================
+ Hits          9650     9749      +99     
- Misses        1634     1635       +1     
Impacted Files Coverage Δ
skfda/tests/test_fpca_regression.py 98.14% <98.14%> (ø)
...da/misc/operators/_linear_differential_operator.py 95.91% <100.00%> (+0.17%) ⬆️
skfda/ml/regression/_fpca_regression.py 100.00% <100.00%> (ø)
skfda/representation/basis/_custom_basis.py 86.25% <100.00%> (+0.53%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@vnmabus vnmabus left a comment

Choose a reason for hiding this comment

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

I think this functionality is implemented in the package fda.usc. We should have a test verifying that we obtain the same results.

skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
examples/plot_fpca_regression.py Outdated Show resolved Hide resolved
examples/plot_fpca_regression.py Show resolved Hide resolved
@Ddelval
Copy link
Contributor Author

Ddelval commented Oct 2, 2022

I think this functionality is implemented in the package fda.usc. We should have a test verifying that we obtain the same results.

I have (finally) added this test. However, while going back and forth between python and R, I stumbled upon a python packet that provides a simple way to execute R code from within python. I am sceptical regarding whether or not this could be useful for the tests. On the one hand, it would ensure that the tests are testing against the correct values while forcing us to include the R source used to obtain the test reference data. On the other hand, it would make the tests considerably slower and require modifications to the GitHub actions.

I think the timing tradeoff is too significant (I measured a slowdown of around 6x). Nevertheless, I thought I might just mention it just in case it comes in handy at some point. The following snippet generates the testing data for the test I just added.

from rpy2 import robjects

Rresult = robjects.r('''
library("fda.usc")
data(tecator)
# Fit the regression model with the first 129 observations
x=tecator$absorp.fdata[1:129,]
y=tecator$y$Fat[1:129]
res2=fregre.pc(x,y,l=1:10)

# Predict the response for the remaining observations
n = length(tecator$y$Fat)
xnew=tecator$absorp.fdata[130:n,]
result = predict(res2, xnew)
names(result) = NULL

# Output the predicted values
paste(
    round(result,8),
    collapse = ", "
)
''')
r_predictions = np.array(Rresult[0].split(", "), dtype=np.float64)

@Ddelval Ddelval requested a review from vnmabus October 2, 2022 11:41
skfda/ml/regression/__init__.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Show resolved Hide resolved
skfda/representation/basis/_custom_basis.py Outdated Show resolved Hide resolved
Copy link
Member

@vnmabus vnmabus left a comment

Choose a reason for hiding this comment

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

Remember to also add the class to the API reference documentation.

skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
skfda/representation/basis/_custom_basis.py Show resolved Hide resolved
"""Check that the results obtained are similar to those of fda.usc.

Results obtained from fda.usc with the following R code
library("fda.usc")
Copy link
Member

Choose a reason for hiding this comment

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

Were you able to compare results with refund too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the issue that I opened: refunders/refund#102.
It doesn't seem like we'll be getting any solutions from their side anytime soon.

@Ddelval Ddelval requested a review from vnmabus February 28, 2023 17:06
"""
from ...misc import inner_product_matrix

if isinstance(self.fdata, FDataBasis):
Copy link
Member

Choose a reason for hiding this comment

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

Why is this specialized for FDataBasis?

Copy link
Contributor Author

@Ddelval Ddelval Mar 1, 2023

Choose a reason for hiding this comment

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

Leftover from the previous implementation. Removed now.

skfda/ml/regression/_fpca_regression.py Outdated Show resolved Hide resolved
@vnmabus vnmabus merged commit cc26782 into develop Mar 1, 2023
@vnmabus vnmabus deleted the feature/FPCA_Regression branch August 17, 2023 10:54
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.

2 participants