Я использую этот Deep Belief Network репозиторий, размещенный на GitHub , для создания моего DBN. Я получаю AttributeError: 'SupervisedDBNClassification' object has no attribute 'loss'
, когда пытаюсь проверить гиперпараметры с помощью утилиты GridSearch
Keras
. Для приведенного ниже примера кода я тестирую гиперпараметр learning_rate
. Ошибка выдается, когда я звоню grid.fit(X_test, Y_test)
.
Вот пример кода:
def create_model_learning_rate(learning_rate):
model = SupervisedDBNClassification(hidden_layers_structure=[64, 64],
learning_rate_rbm=learning_rate,
n_epochs_rbm=10,
n_iter_backprop=20,
batch_size=32,
activation_function='relu',
dropout_p=0.2)
return model
def grid_search():
epochs = 20
batch_size = 32
model = KerasClassifier(build_fn=create_model_learning_rate, epochs=epochs, batch_size=batch_size, verbose=0)
param_grid = dict(learning_rate=[0.01, 0.001])
feature_matrix, target_matrix = create_feature_target_vectors()
X_train, X_test, Y_train, Y_test = train_test_split(feature_matrix, target_matrix, test_size=0.2, random_state=random_state)
grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1, cv=3)
grid_result = grid.fit(X_test, Y_test)
print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))
means = grid_result.cv_results_['mean_test_score']
stds = grid_result.cv_results_['std_test_score']
params = grid_result.cv_results_['params']
for mean, stdev, param in zip(means, stds, params):
print("%f (%f) with: %r" % (mean, stdev, param))