gridsearchCV result score가 동일하게 나옵니다.
import numpy
from sklearn.model_selection import GridSearchCV
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier
#load data
data = pd.read_csv('~/all.csv')
df - data.iloc[:, 4:]
X = pd.DataFrame(df.values)
Y = pd.DataFrame(data, columns=['number'])
X_train, X_test, Y_train, Y_test = train_test_split(X.values, Y.values, test_size=0.1, random_state=42)
# Function to create model, required for KerasClassifier
def create_model(neurons=256):
# create model
model = Sequential()
model.add(Dense(neurons, input_dim=8192, activation='sigmoid'))
model.add(Dense(neurons, activation='sigmoid'))
model.add(Dense(neurons, activation='sigmoid'))
model.add(Dense(neurons, activation='sigmoid'))
model.add(Dense(1, activation='linear'))
# Compile model
model.compile(loss='mae', optimizer='adam')
return model
# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)
model = KerasClassifier(build_fn=create_model, verbose=0, batch_size = 8)
# define the grid search parameters
neurons = [256]
epochs = [32, 64]
param_grid = dict(neurons=neurons, epochs=epochs)
grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1, cv=3, scoring='r2')
grid_result = grid.fit(X_train, Y_train)
# summarize results
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))
코드입니다.
이렇게 실행시키면 결과값이 모두 동일한 값이 나와요.
Best: -16.710561 using {'epochs': 32, 'neurons': 256}
-16.710561 (5.419502) with {'epochs': 32, 'neurons': 256}
-16.710561 (5.419502) with {'epochs': 64, 'neurons': 256}
위 값 뿐만아니라 mean_test_socre 등 모든 값이 동일하게 나와 최적의 parameter를 구할수 없습니다.
무엇이 문제인지 알려주세요.