Сначала я начал с освобождения места.
Код: Выделить всё
# Reseting layers and freeing up some space
tf.keras.backend.clear_session()
Код: Выделить всё
def create_model(learning_rate=0.02):
model = Sequential([
Dense(128, activation='relu', input_shape=(23,)), #Input Layer
Dense(64, activation='relu'), #Hidden Layer
Dense(7, activation='softmax') #Output Layer
])
# Compiling Model
from tensorflow.keras.optimizers import Adam
model.compile(optimizer=Adam(learning_rate=learning_rate), loss='sparse_categorical_crossentropy', metrics=['accuracy', map_3])
return model
Код: Выделить всё
# Early Stopping
from tensorflow.keras.callbacks import EarlyStopping
early_stopping = EarlyStopping(monitor = 'val_map_3',
patience = 5,
mode = 'max',
restore_best_weights=True)
Код: Выделить всё
# Setting Parameters for Randomized Search CV
param_dict = {'epochs': [20, 40, 60, 80, 100, 120, 150],
'batch_size': [32, 64, 128, 256, 512, 1024],
'learning_rate': [0.04, 0.06, 0.08, 0.1, 0.2, 0.5, 1.0, 2.0]}
Код: Выделить всё
from scikeras.wrappers import KerasClassifier
tunned_model = KerasClassifier(
model=create_model,
epochs=param_dict['epochs'],
batch_size=param_dict['batch_size'],
learning_rate=param_dict['learning_rate'], verbose=1)
Код: Выделить всё
# Loading Randomized Search CV
random_search = RandomizedSearchCV(tunned_model, param_distributions=param_dict, n_iter= 20, scoring='accuracy', verbose=2, cv=5, n_jobs=1, refit=True)
# Fitting Neural Network
random_search.fit(
X_train,
y_train,
validation_data=(X_val, y_val),
callbacks=[early_stopping]
)
Output:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in ()
3
4 # Fitting Neural Network
----> 5 random_search.fit(
6 X_train,
7 y_train,
4 frames
/usr/local/lib/python3.11/dist-packages/sklearn/base.py in __sklearn_tags__(self)
538
539 def __sklearn_tags__(self):
--> 540 tags = super().__sklearn_tags__()
541 tags.estimator_type = "classifier"
542 tags.classifier_tags = ClassifierTags()
AttributeError: 'super' object has no attribute '__sklearn_tags__'
Подробнее здесь: https://stackoverflow.com/questions/796 ... al-network
Мобильная версия