[Python] Grid search error : 'super' object has no attribute '__sklearn_tags__'

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to run a gridsearch in my pycharm jupyter notebook.

    Getting 'super' object has no attribute 'sklearn_tags' error. This question was asked for RandomizedSearch previously. But none of the answers seem to work for me.

    The cell which does the import

    import boto3
    import pandas as pd
    import re
    import time
    from sklearn.model_selection import train_test_split
    import concurrent.futures
    import tensorflow as tf
    from sklearn.preprocessing import normalize
    from scikeras.wrappers import KerasClassifier
    import numpy as np
    from keras.api.models import Sequential
    from keras.api.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout
    from keras.api.optimizers import Adam, SGD
    from sklearn.model_selection import GridSearchCV


    The code which is written to do the GridSearch:

    def create_model2(optimizer='adam', learning_rate=0.001, dropout_rate=0.5,
    momentum=0.0, beta_1=0.9):

    if optimizer == 'adam':
    opt = Adam(learning_rate=learning_rate, beta_1=beta_1)
    elif optimizer == 'sgd':
    opt = SGD(learning_rate=learning_rate, momentum=momentum)
    else:
    raise ValueError("Unsupported optimizer")

    model = Sequential()
    model.add(Conv2D(32, (3,3), activation='relu', input_shape=(28,28,1)))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(Flatten())
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(dropout_rate))
    model.add(Dense(10, activation='softmax'))

    model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])
    return model


    model = KerasClassifier(build_fn=create_model2, verbose=0)

    param_grid = {
    'optimizer': ['adam', 'sgd'],
    'learning_rate': [0.001],
    'dropout_rate': [0.3],
    'batch_size': [64],
    'epochs': [5],
    'momentum': [0.9],
    'beta_1': [0.9]
    }

    grid = GridSearchCV(estimator=model, param_grid=param_grid, cv=2, n_jobs=1)
    grid_result = grid.fit(x_train_normalized, y_train)

    print("Best Grid Score: %.4f using %s" % (grid_result.best_score_, grid_result.best_params_)


    The requirements file :

    pyspark==3.5.1
    findspark
    seaborn
    scipy
    pyarrow
    pandas
    scikit-learn==1.5.2
    matplotlib
    s3fs
    mlxtend
    pypdf==5.4.0
    reportlab
    graphviz
    pydotplus
    tensorflow==2.16.1
    keras==3.9.2
    scikeras


    Error trace :

    ---------------------------------------------------------------------------
    AttributeError Traceback (most recent call last)
    Cell In[123], line 36
    25 param_grid = {
    26 'optimizer': ['adam', 'sgd'],
    27 'learning_rate': [0.001],
    (...) 32 'beta_1': [0.9]
    33 }
    35 grid = GridSearchCV(estimator=model, param_grid=param_grid, cv=2, n_jobs=1)
    ---> 36 grid_result = grid.fit(x_train_normalized, y_train)

    AttributeError: 'super' object has no attribute '__sklearn_tags__'


    I know there is a similar question here ,but thats for RandomizedSearch and none of the answers given work for me.

    'super' object has no attribute '__sklearn_tags__'

    How can I run the gridsearch cv by changing any of the above snippets ? I need to find the best optimizer among adam, sgd, RMSProp etc.... for my training dataframe.

    Continue reading...

Compartilhe esta Página