MCPcopy Index your code
hub / github.com/rushter/MLAlgorithms / classification

Function classification

examples/random_forest.py:19–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17
18
19def 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
45def regression():

Callers 1

random_forest.pyFile · 0.70

Calls 3

fitMethod · 0.45
predictMethod · 0.45

Tested by

no test coverage detected