'How to gridsearch RBFSampler

I want to gridsearch RBFSampler in LightGBM. I don't want to change any params of LightGBM, just the params of RBFSampler. I am having trouble figuring out where to run my features (X) through RBFSampler.

Code:

gamma = [.1,1,10]
n_components = [10,100,1000]
param_grid = {
    "gamma": gamma,
    "n_components": n_components,
    }
search = GridSearchCV(
    LGBMClassifier(n_jobs=-1,verbosity=0)
    ,param_grid=param_grid,n_jobs=-1,cv=tscv,verbose=0,
)

search.fit(X, y)


Solution 1:[1]

You need a pipeline to collect the RBFSampler together with the model.

from sklearn.pipeline import Pipeline

pipe = Pipeline([
    ('rbfs', RBFSampler()),
    ('lgbm', LGBMClassifier(n_jobs=-1, verbosity=0)),
])

param_grid = {
    "rbfs__gamma": gamma,
    "rbfs__n_components": n_components,
}

search = GridSearchCV(
    pipe,
    param_grid=param_grid,
    ...
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ben Reiniger