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

Density weighted linear regression #12

Open
loicdtx opened this issue Jun 24, 2024 · 0 comments
Open

Density weighted linear regression #12

loicdtx opened this issue Jun 24, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@loicdtx
Copy link
Collaborator

loicdtx commented Jun 24, 2024

A single "winter outlier" can sometimes have a large influence on the model fit. Winter observation are often less dense and of lower quality; reducing their weight in the regression could help having more stable models. Implementing density weighted linear regression as a fit_method could be useful.

How?

  • Compute density using Kernel Density Estimation
  • Use density as weight in the regression

Pseudo code:

import numpy as np
from scipy.stats import gaussian_kde

kde = gaussian_kde(X, bw_method=0.5)
density = kde(X)

W = np.diag(density)
XTWX = np.dot(np.dot(X.T, W), X)
XTWy = np.dot(np.dot(X.T, W), y)
beta = np.linalg.solve(XTWX, XTWy)
@loicdtx loicdtx added the enhancement New feature or request label Jun 24, 2024
@loicdtx loicdtx self-assigned this Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant