1
- from timeit import default_timer
2
- start = default_timer ()
3
1
import logging
4
2
5
3
import numpy as np
6
- from sklearn .datasets import make_classification , load_boston , load_digits , load_breast_cancer , load_iris
4
+ from sklearn .datasets import make_classification
7
5
from sklearn .datasets import make_regression
8
6
from sklearn .metrics import roc_auc_score , accuracy_score
9
7
@@ -23,16 +21,17 @@ def classification():
23
21
X , y = make_classification (
24
22
n_samples = 500 , n_features = 10 , n_informative = 10 , random_state = 1111 , n_classes = 2 , class_sep = 2.5 , n_redundant = 0
25
23
)
26
- #X,y = load_breast_cancer(return_X_y=True)
27
24
28
25
X_train , X_test , y_train , y_test = train_test_split (X , y , test_size = 0.15 , random_state = 1111 )
29
26
30
- model = RandomForestClassifier (n_estimators = 5 , max_depth = 4 )
27
+ model = RandomForestClassifier (n_estimators = 10 , max_depth = 4 )
31
28
model .fit (X_train , y_train )
32
- predictions = model .predict (X_test )[:,1 ]
33
- #predictions = np.argmax(model.predict(X_test),axis=1)
34
- print (predictions .shape )
35
- print ("classification, roc auc score: %s" % roc_auc_score (y_test , predictions ))
29
+
30
+ predictions_prob = model .predict (X_test )[:, 1 ]
31
+ predictions = np .argmax (model .predict (X_test ), axis = 1 )
32
+ #print(predictions.shape)
33
+ print ("classification, roc auc score: %s" % roc_auc_score (y_test , predictions_prob ))
34
+ print ("classification, accuracy score: %s" % accuracy_score (y_test , predictions ))
36
35
37
36
38
37
def regression ():
@@ -51,5 +50,3 @@ def regression():
51
50
if __name__ == "__main__" :
52
51
classification ()
53
52
# regression()
54
- end = default_timer ()
55
- print (end - start )
0 commit comments