Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- num_folds = 10
- n_jobs = -1
- score = 'recall'
- pipe_nn = Pipeline([['sc', StandardScaler()],
- ['NN', MLPClassifier(random_state=rand_state,
- alpha(0.05), hidden_layer_sizes(100,),
- activation('relu')]])
- scores_nn = cross_val_score(estimator=pipe_nn,X=X_train,y=y_train,cv=num_folds,n_jobs=n_jobs, scoring=score)
- Training Accuracy: 0.735
- Test Accuracy: 0.691
- pred:yes pred:no
- act:yes 129 26
- act:no 81 110
- precision recall f1-score support
- 0 0.61 0.83 0.71 155
- 1 0.81 0.58 0.67 191
- avg / total 0.72 0.69 0.69 346
- pipe_nn = Pipeline([['sc', StandardScaler()],
- ['PCA',PCA(random_state=rand_state)],
- ['NN', MLPClassifier(random_state=rand_state)]])
- # Hyperparameters
- param_grid = dict(PCA = [None,PCA(2),PCA(4),PCA(6),PCA(9),PCA(10),PCA(12),PCA(15),PCA(18)],
- MLP__hidden_layer_sizes = [(100,), (50,100), (50,100,50)],
- NN__activation = ['tanh', 'relu'],
- NN__alpha = [0.0001, 0.05])
- # Apply grid search
- grid_nn = GridSearchCV(estimator=pipe_nn,
- param_grid=param_grid,
- cv=num_folds,
- scoring=score)
- gs_nn = grid_nn.fit(X_train, y_train)
- Best Parameters: {'PCA': PCA(n_components=18), 'NN__alpha': 0.0001,
- 'NN__hidden_layer_sizes': (10, 50), 'NN__activation': 'relu'}
- Training Accuracy: 0.761
- Test Accuracy : 0.728
- pred:yes pred:no
- act:yes 117 38
- act:no 56 135
- precision recall f1-score support
- 0 0.68 0.75 0.71 155
- 1 0.78 0.71 0.74 191
- avg / total 0.73 0.73 0.73 346
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement