MLPClassifier(activation='relu', alpha=0.0001, batch_size=1000, beta_1=0.9,
beta_2=0.999, early_stopping=False, epsilon=1e-08,
hidden_layer_sizes=(100,), learning_rate='constant',
learning_rate_init=0.001, max_iter=200, momentum=0.9,
n_iter_no_change=10, nesterovs_momentum=True, power_t=0.5,
random_state=1, shuffle=True, solver='adam', tol=0.0001,
validation_fraction=0.1, verbose=False, warm_start=False). Check the list of available parameters with `estimator.get_params().keys()`.
pred=np.array([pred2,pred4,pred5]).T
#pred=np.array([pred1,pred2,pred3,pred4]).T
#output layer containg y_test
out=Y
#split dataset
#from sklearn.model_selection import train_test_split
X_train1, X_test1, y_train1, y_test1 = model_selection.train_test_split(pred,out,test_size=0.3, random_state=123)
#param_grid = {
# 'activation' : ['identity', 'logistic', 'tanh', 'relu'],
# 'solver' :['lbfgs', 'sgd', 'adam'] ,
# 'alpha':[0.0001,1e-5,0.01,0.001],
# 'batch_size' :[1000,5000],
# 'learning_rate':['constant', 'invscaling', 'adaptive'] ,
# 'learning_rate_init':[0.001,0.01,0.1,0.2,0.3]
#}
layers=[[3],[4],[3,3],[3,4],[3,5]]
activation=['relu', 'identity', 'tanh', 'logistic']
solver=['lbfgs', 'sgd', 'adam']
alpha=[0.0001,1e-5,0.01,0.001]
batch_size=[1000,5000]
learning_rate=['constant', 'invscaling', 'adaptive']
learning_rate_init=[0.001,0.01,0.1,0.2,0.3]
param_grid=dict(layers=layers, activation=activation, batch_size=batch_size,learning_rate=learning_rate,learning_rate_init=learning_rate_init)
mlp = MLPClassifier(random_state=1)
grid = GridSearchCV(mlp, param_grid, cv=10, scoring='accuracy')
grid_result=grid.fit(X_train1, y_train1)
grid_result
#solver='lbfgs', alpha=1e-5,hidden_layer_sizes=(4, 8),activation='relu',
#clf = GridSearchCV(mlp,param_grid,cv=10, scoring = 'accuracy',n_jobs=-1)
#clf.fit(pred, out)
#print('\t\Best:%f using %s' % (clf.best_score_ , clf.best_params_))
print("Best Hyper Parameters:\n",grid.best_params_)
#Prediction
prediction=grid.predict(X_test1)
t = time() - t0
print("=" * 52)
print("time cost: {}".format(t))
print()
#importing the metrics module
from sklearn import metrics
#evaluation(Accuracy)
print("Accuracy:",metrics.accuracy_score(prediction,y_test1))
#evaluation(Confusion Metrix)
print("Confusion Metrix:\n",metrics.confusion_matrix(prediction,y_test1))
print()
print("\t\taccuracy: {}".format(metrics.accuracy_score(prediction, y_test1)))
print(metrics.classification_report(prediction,y_test1))
答案 0 :(得分:2)
由于无效的参数图层而将图层更改为hidden_layer_sizes引起了问题