()
| 17 | |
| 18 | |
| 19 | def classification(): |
| 20 | # Generate a random binary classification problem. |
| 21 | X, y = make_classification( |
| 22 | n_samples=500, |
| 23 | n_features=10, |
| 24 | n_informative=10, |
| 25 | random_state=1111, |
| 26 | n_classes=2, |
| 27 | class_sep=2.5, |
| 28 | n_redundant=0, |
| 29 | ) |
| 30 | |
| 31 | X_train, X_test, y_train, y_test = train_test_split( |
| 32 | X, y, test_size=0.15, random_state=1111 |
| 33 | ) |
| 34 | |
| 35 | model = RandomForestClassifier(n_estimators=10, max_depth=4) |
| 36 | model.fit(X_train, y_train) |
| 37 | |
| 38 | predictions_prob = model.predict(X_test)[:, 1] |
| 39 | predictions = np.argmax(model.predict(X_test), axis=1) |
| 40 | # print(predictions.shape) |
| 41 | print("classification, roc auc score: %s" % roc_auc_score(y_test, predictions_prob)) |
| 42 | print("classification, accuracy score: %s" % accuracy_score(y_test, predictions)) |
| 43 | |
| 44 | |
| 45 | def regression(): |
no test coverage detected