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

Error in LinearRegression.fit with TensorBasis #641

Open
yanxiuJin opened this issue Jan 12, 2025 · 1 comment
Open

Error in LinearRegression.fit with TensorBasis #641

yanxiuJin opened this issue Jan 12, 2025 · 1 comment

Comments

@yanxiuJin
Copy link

Hello,

I am trying to use skfda.ml.regression.LinearRegression for a functional linear regression task with TensorBasis. My functional data is defined on a 2D domain (time grid of hours and days). I used a TensorBasis consisting of a FourierBasis (for hours) and a BSplineBasis (for days) to represent my functional data. However, an error is raised during model fitting:

Here is a simplified example of my setup:

import numpy as np
from skfda.representation.grid import FDataGrid
from skfda.representation.basis import TensorBasis, FourierBasis, BSplineBasis
from skfda.ml.regression import LinearRegression
import pandas as pd

hours = np.linspace(1, 24, 24) 
days = np.linspace(1, 7, 7)  
grid_points = [hours, days]

N = 10  # Number of samples
x_data = np.random.rand(N, 24, 7)  # Functional covariates
y_data = np.random.rand(N, 24, 7)  # Functional response

x_grid = FDataGrid(data_matrix=x_data, grid_points=grid_points)
y_grid = FDataGrid(data_matrix=y_data, grid_points=grid_points)

# Define basis for TensorBasis representation
x_basis = TensorBasis([
    FourierBasis(n_basis=3, domain_range=(1, 24)),  
    BSplineBasis(n_basis=4, domain_range=(1, 7)),  
])
y_basis = TensorBasis([
    FourierBasis(n_basis=3, domain_range=(1, 24)), 
    BSplineBasis(n_basis=4, domain_range=(1, 7)),  
])

# Convert FDataGrid to basis representation
X_train = pd.DataFrame({"covariate": x_grid.to_basis(x_basis)})
Y_train = y_grid.to_basis(y_basis)


linear_reg = LinearRegression(coef_basis=[x_basis])
linear_reg.fit(X_train, Y_train)

Error Message:
TypeError: LinearRegression._weighted_inner_product_integrate.<locals>.integrand() takes 1 positional argument but 2 were given

Environment:
scikit-fda version: [0.9.2.dev0]
Python version: [3.10.15]

I would like to know if LinearRegression currently supports using TensorBasis? If it does, are there any specific configurations or settings required for it to work properly?
Thank you for your attention.

@vnmabus
Copy link
Member

vnmabus commented Jan 13, 2025

If I am not mistaken, we do not currently support functions of several variables in the linear regression code. I think it should not be too hard to add support for it, but currently we do not have the bandwidth for implementing that feature.

I will leave the issue open, so that we do not lose track of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants