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] Add LinearEmbedder model to the mix. #695

Open
koaning opened this issue Aug 14, 2024 · 1 comment
Open

[FEATURE] Add LinearEmbedder model to the mix. #695

koaning opened this issue Aug 14, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@koaning
Copy link
Owner

koaning commented Aug 14, 2024

In this live stream I seem to be able to show that KNN can perform on par with boosted models once you improve the representation of X. A quick trick to do this is to first run a linear model and to use the trained coefficients to rescale X before indexing it.

This implementation shows the idea:

from sklearn.base import BaseEstimator, RegressorMixin

class RidgeKNNRegressor(BaseEstimator, RegressorMixin):
    def __init__(self, n_neighbors=5, coef_fit=False, weights="uniform"):
        self.n_neighbors = n_neighbors
        self.coef_fit = coef_fit
        self.weights = weights

    def fit(self, X, y):
        if self.coef_fit:
            self.mod_ = Ridge(fit_intercept=False).fit(X, y)
            X = X * mod.coef_
        self.knn_ = KNeighborsRegressor(n_neighbors=self.n_neighbors, weights=self.weights).fit(X, y)
        return self

    def predict(self, X):
        if self.coef_fit:
            X = X * mod.coef_
        return self.knn_.predict(X)

Instead of doing both the embedding and the KNN in one go though I think it will be nicer to split this and to have a dedicated (meta?) estimator that can add context to X.

@FBruzzesi I can pick this up, but feel free to tell me if you doubt this idea.

@koaning koaning added the enhancement New feature or request label Aug 14, 2024
@koaning koaning self-assigned this Aug 14, 2024
@FBruzzesi
Copy link
Collaborator

That sounds a fun one to have 🙌🏼

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

2 participants