()
| 21 | |
| 22 | |
| 23 | def classification(): |
| 24 | # Generate a random binary classification problem. |
| 25 | X, y = make_classification( |
| 26 | n_samples=1000, |
| 27 | n_features=100, |
| 28 | n_informative=75, |
| 29 | random_state=1111, |
| 30 | n_classes=2, |
| 31 | class_sep=2.5, |
| 32 | ) |
| 33 | y = one_hot(y) |
| 34 | X_train, X_test, y_train, y_test = train_test_split( |
| 35 | X, y, test_size=0.15, random_state=1111 |
| 36 | ) |
| 37 | |
| 38 | model = NeuralNet( |
| 39 | layers=[ |
| 40 | Dense(256, Parameters(init="uniform", regularizers={"W": L2(0.05)})), |
| 41 | Activation("relu"), |
| 42 | Dropout(0.5), |
| 43 | Dense(128, Parameters(init="normal", constraints={"W": MaxNorm()})), |
| 44 | Activation("relu"), |
| 45 | Dense(2), |
| 46 | Activation("softmax"), |
| 47 | ], |
| 48 | loss="categorical_crossentropy", |
| 49 | optimizer=Adadelta(), |
| 50 | metric="accuracy", |
| 51 | batch_size=64, |
| 52 | max_epochs=25, |
| 53 | ) |
| 54 | model.fit(X_train, y_train) |
| 55 | predictions = model.predict(X_test) |
| 56 | print("classification accuracy", roc_auc_score(y_test[:, 0], predictions[:, 0])) |
| 57 | |
| 58 | |
| 59 | def regression(): |
no test coverage detected