analist commited on
Commit
b1e8012
·
verified ·
1 Parent(s): 21e0424

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -2
app.py CHANGED
@@ -5,7 +5,69 @@ import matplotlib.pyplot as plt
5
  from sklearn.tree import plot_tree, export_text
6
  import seaborn as sns
7
  from sklearn.preprocessing import LabelEncoder
8
- import joblib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  def load_model_and_data():
11
  # Ici vous chargeriez votre modèle et données
@@ -14,7 +76,7 @@ def load_model_and_data():
14
  # X = loaded_X
15
  # y = loaded_y
16
  # feature_names = X.columns
17
- model = joblib.load('DecisionTreeModel.joblib')
18
  data = pd.read_csv('exported_named_train.csv')
19
  X = data.drop("Target", axis=1)
20
  y = data['Target']
 
5
  from sklearn.tree import plot_tree, export_text
6
  import seaborn as sns
7
  from sklearn.preprocessing import LabelEncoder
8
+ from sklearn.ensemble import RandomForestClassifier
9
+ from sklearn.tree import DecisionTreeClassifier, plot_tree
10
+ from sklearn.ensemble import GradientBoostingClassifier
11
+ from sklearn.linear_model import LogisticRegression
12
+ from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, roc_auc_score, roc_curve
13
+
14
+ data = pd.read_csv('exported_named_train.csv')
15
+ X_train = data.drop("Target", axis=1).values
16
+ y_train = data['Target'].values
17
+
18
+ models={
19
+ "Logisitic Regression":LogisticRegression(),
20
+ "Decision Tree":DecisionTreeClassifier(),
21
+ "Random Forest":RandomForestClassifier(),
22
+ "Gradient Boost":GradientBoostingClassifier()
23
+ }
24
+
25
+ for name, model in models.items():
26
+
27
+ model.fit(X_train, y_train)
28
+
29
+ # Make predictions
30
+ y_train_pred = model.predict(X_train)
31
+ y_test_pred = model.predict(X_test)
32
+
33
+ # Training set performance
34
+ model_train_accuracy = accuracy_score(y_train, y_train_pred) # Calculate Accuracy
35
+ model_train_f1 = f1_score(y_train, y_train_pred, average='weighted') # Calculate F1-score
36
+ model_train_precision = precision_score(y_train, y_train_pred) # Calculate Precision
37
+ model_train_recall = recall_score(y_train, y_train_pred) # Calculate Recall
38
+ model_train_rocauc_score = roc_auc_score(y_train, y_train_pred)
39
+
40
+ # Test set performance
41
+ model_test_accuracy = accuracy_score(y_test, y_test_pred) # Calculate Accuracy
42
+ model_test_f1 = f1_score(y_test, y_test_pred, average='weighted') # Calculate F1-score
43
+ model_test_precision = precision_score(y_test, y_test_pred) # Calculate Precision
44
+ model_test_recall = recall_score(y_test, y_test_pred) # Calculate Recall
45
+ model_test_rocauc_score = roc_auc_score(y_test, y_test_pred) #Calculate Roc
46
+
47
+ print(name)
48
+
49
+ print('Model performance for Training set')
50
+ print("- Accuracy: {:.4f}".format(model_train_accuracy))
51
+ print('- F1 score: {:.4f}'.format(model_train_f1))
52
+
53
+ print('- Precision: {:.4f}'.format(model_train_precision))
54
+ print('- Recall: {:.4f}'.format(model_train_recall))
55
+ print('- Roc Auc Score: {:.4f}'.format(model_train_rocauc_score))
56
+
57
+
58
+
59
+ print('----------------------------------')
60
+
61
+ print('Model performance for Test set')
62
+ print('- Accuracy: {:.4f}'.format(model_test_accuracy))
63
+ print('- F1 score: {:.4f}'.format(model_test_f1))
64
+ print('- Precision: {:.4f}'.format(model_test_precision))
65
+ print('- Recall: {:.4f}'.format(model_test_recall))
66
+ print('- Roc Auc Score: {:.4f}'.format(model_test_rocauc_score))
67
+
68
+
69
+ print('='*35)
70
+ print('\n')
71
 
72
  def load_model_and_data():
73
  # Ici vous chargeriez votre modèle et données
 
76
  # X = loaded_X
77
  # y = loaded_y
78
  # feature_names = X.columns
79
+ model = models['Decision Tree']
80
  data = pd.read_csv('exported_named_train.csv')
81
  X = data.drop("Target", axis=1)
82
  y = data['Target']