Время выполнения GridSearch / прогресс - PullRequest
0 голосов
/ 18 января 2020

Доброе утро, я попытался запустить gridsearchCV, чтобы найти лучшие гиперпараметры для полностью подключенной нейронной сети. Но это займет много времени, чтобы завершить его. Есть ли способ узнать, сколько времени занимает бег? Или способ понять, сколько комбинаций гиперпараметров было «изучено»? Ниже вы можете найти код. Спасибо

import numpy as np

from keras.wrappers.scikit_learn import KerasRegressor
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from matplotlib import pyplot as plt
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import r2_score


dataset = pd.read_csv('DataSet.csv', decimal=',', delimiter = ";")

label = dataset.iloc[:,-1]
features = dataset.drop(columns = ['Label'])
features = features[best_features]

y_max_pre_normalize = max(label)
y_min_pre_normalize = min(label)

def denormalize(y):
    final_value = y*(y_max_pre_normalize-y_min_pre_normalize)+y_min_pre_normalize
    return final_value

X_train1, X_test1, y_train1, y_test1 = train_test_split(features, label, test_size = 0.20, shuffle = True)

y_test2 = y_test1.to_frame()
y_train2 = y_train1.to_frame()

# =============================================================================
# Normalizzo
# =============================================================================
scaler1 = preprocessing.MinMaxScaler()
scaler2 = preprocessing.MinMaxScaler()
X_train = scaler1.fit_transform(X_train1)
X_test = scaler2.fit_transform(X_test1)


scaler3 = preprocessing.MinMaxScaler()
scaler4 = preprocessing.MinMaxScaler()
y_train = scaler3.fit_transform(y_train2)
y_test = scaler4.fit_transform(y_test2)
# =============================================================================
# # Creo la rete
# =============================================================================
def build_regressor(opti, units1, units2, units3, acti, a, kern):

    model = Sequential()
    model.add(Dense(units = units1, input_shape = (features.shape[1],), activation = acti, kernel_initializer = kern))
    model.add(Dropout(a))
    model.add(Dense(units = units2, activation = acti, kernel_initializer = kern))
    model.add(Dropout(a))
    model.add(Dense(units = units3, activation = acti, kernel_initializer = kern))
    model.add(Dense(1,activation = 'linear'))
    model.compile(loss = 'mse', optimizer = opti, metrics = ['mse'])
    return model



parameters ={'units1' : [50,100,150,],
             'units2' : [50,100,150],
             'units3' : [50,100,150],
              'batch_size' : [50,100,200,400,800],
              'kern':['random_normal','random_uniform','VarianceScaling'],
              'epochs': [100,150,200],
              'acti':['relu','sigmoid','linear','tanh'],
              'opti':[tf.keras.optimizers.Adamax(lr=0.001),
                      tf.keras.optimizers.Adam(lr=0.001)],
              'a' : [0.2,0.3,0.4,0.5]
                          }
regressor = KerasRegressor(build_fn = build_regressor, verbose = 1)

gridSearch = GridSearchCV(estimator=regressor,
                          param_grid=parameters,
                          cv=5
                          )



grid_result = gridSearch.fit(X_train, y_train)

print('Grid Search Best score',gridSearch.best_score_)
print('Grid Search Best Parameters', gridSearch.best_params_)
print('Execution time',gridSearch.refit_time_)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...