Skip to content

GridSearchCV FactorAnalyzer error #72

Description

@gneusch

Hi Jeremy,
How are you?
I ran into an error I cannot solve, and I don't find any clue on the internet. I tried to integrate a FactorAnalyzer into an sklearn GridSearchCV. As far as I know as it has a fit and a transform method it should work, shouldn't it? But unfortunately I'm running into the following error:

RuntimeError: Cannot clone object FactorAnalyzer(rotation_kwargs={}), as the constructor either does not set or modifies parameter impute

I tried to set impute directly in the constructor, I also tried to add it to the param_grid dict, but none of those work, same error. Is this a known issue? Should it work at all? Is there a workaround you know about? Maybe it has to do something with this answer?

Thanks a million in advance for your kind help!

Here is my code for reference:

ppln_pca_param_grid = {'decisiontreeclassifier__max_depth': np.arange(2, 15),
                   'decisiontreeclassifier__min_samples_leaf': np.arange(5,10),
                   'decisiontreeclassifier__ccp_alpha': np.arange(0., 0.003, 0.0003).tolist(),            
                   'decisiontreeclassifier__criterion': ['gini', 'entropy'],
                   'smote__sampling_strategy': np.arange(0.3, 1., 0.1).tolist(),
                   'factoranalyzer__n_components':[2, 3, 4, 5],
                   'factoranalyzer__impute':['median'],
                   'factoranalyzer__rotation':['varimax']                      
                    }

scaler = StandardScaler()
resampler = SMOTE(random_state=123)
fa = FactorAnalyzer()
dt = DecisionTreeClassifier(random_state=123)

imba_pca_pipeline = make_pipeline(resampler, scaler, fa, dt)

gscv_pca_imba_f1 = GridSearchCV(imba_pca_pipeline, ppln_pca_param_grid, scoring='f1', cv=10, n_jobs = 4, verbose = 2)
gscv_pca_imba_f1.fit(train_df_pca[features], train_df_pca['hit'])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions