1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| import pandas as pd from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, roc_curve import numpy as np
data = np.asarray(pd.read_csv('data.csv')) x = data[:, 0:2] y = data[:, 2]
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=42)
model = DecisionTreeClassifier() model.fit(x_train, y_train) y_pred = model.predict(x_test)
acc = accuracy_score(y_test, y_pred) precision_score = precision_score(y_test, y_pred) recall_score = recall_score(y_test, y_pred) f1_score = f1_score(y_test, y_pred) roc_curve = roc_curve(y_test, y_pred)
print('acc: ', acc) print('precision_score: ', precision_score) print('recall_score: ', recall_score) print('f1_score: ', f1_score) print('roc_curve: ', roc_curve)
|