Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. num_folds = 10
  2. n_jobs = -1
  3. score = 'recall'
  4.  
  5. pipe_nn = Pipeline([['sc', StandardScaler()],
  6. ['NN', MLPClassifier(random_state=rand_state,
  7. alpha(0.05), hidden_layer_sizes(100,),
  8. activation('relu')]])
  9.  
  10. scores_nn = cross_val_score(estimator=pipe_nn,X=X_train,y=y_train,cv=num_folds,n_jobs=n_jobs, scoring=score)
  11.  
  12. Training Accuracy: 0.735
  13. Test Accuracy: 0.691
  14. pred:yes pred:no
  15. act:yes 129 26
  16. act:no 81 110
  17.  
  18. precision recall f1-score support
  19. 0 0.61 0.83 0.71 155
  20. 1 0.81 0.58 0.67 191
  21. avg / total 0.72 0.69 0.69 346
  22.  
  23. pipe_nn = Pipeline([['sc', StandardScaler()],
  24. ['PCA',PCA(random_state=rand_state)],
  25. ['NN', MLPClassifier(random_state=rand_state)]])
  26.  
  27. # Hyperparameters
  28. param_grid = dict(PCA = [None,PCA(2),PCA(4),PCA(6),PCA(9),PCA(10),PCA(12),PCA(15),PCA(18)],
  29. MLP__hidden_layer_sizes = [(100,), (50,100), (50,100,50)],
  30. NN__activation = ['tanh', 'relu'],
  31. NN__alpha = [0.0001, 0.05])
  32.  
  33. # Apply grid search
  34. grid_nn = GridSearchCV(estimator=pipe_nn,
  35. param_grid=param_grid,
  36. cv=num_folds,
  37. scoring=score)
  38. gs_nn = grid_nn.fit(X_train, y_train)
  39.  
  40. Best Parameters: {'PCA': PCA(n_components=18), 'NN__alpha': 0.0001,
  41. 'NN__hidden_layer_sizes': (10, 50), 'NN__activation': 'relu'}
  42. Training Accuracy: 0.761
  43. Test Accuracy : 0.728
  44.  
  45. pred:yes pred:no
  46. act:yes 117 38
  47. act:no 56 135
  48.  
  49. precision recall f1-score support
  50. 0 0.68 0.75 0.71 155
  51. 1 0.78 0.71 0.74 191
  52. avg / total 0.73 0.73 0.73 346
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement