add metrics and params files

lorendery 5 months ago
parent
commit
041219e9f1
3 changed files with 39 additions and 6 deletions
  1. 2
    0
      code/metrics.csv
  2. 16
    6
      code/modeling.py
  3. 21
    0
      code/params.yml
@@ -1,16 +1,26 @@
 from sklearn.ensemble import RandomForestClassifier
 from sklearn.ensemble import RandomForestClassifier
 from sklearn.metrics import roc_auc_score
 from sklearn.metrics import roc_auc_score
 import pandas as pd
 import pandas as pd
-from src.const import *
+from const import *
+import dagshub
 
 
-print(M_MOD_INIT,'\n'+M_MOD_LOAD_DATA)
+print(M_MOD_INIT, '\n' + M_MOD_LOAD_DATA)
 X_train = pd.read_csv(X_TRAIN_PATH)
 X_train = pd.read_csv(X_TRAIN_PATH)
 X_test = pd.read_csv(X_TEST_PATH)
 X_test = pd.read_csv(X_TEST_PATH)
 y_train = pd.read_csv(Y_TRAIN_PATH)
 y_train = pd.read_csv(Y_TRAIN_PATH)
 y_test = pd.read_csv(Y_TEST_PATH)
 y_test = pd.read_csv(Y_TEST_PATH)
 
 
 print(M_MOD_RFC)
 print(M_MOD_RFC)
-rfc = RandomForestClassifier(n_estimators=1, random_state=0)
-rfc.fit(X_train, y_train.values.ravel())
-y_pred = rfc.predict(X_test)
-print(M_MOD_SCORE, round(roc_auc_score(y_test, y_pred),3))
+with dagshub.dagshub_logger() as logger:
+    rfc = RandomForestClassifier(n_estimators=1, random_state=0)
+    # log the model's parameters
+    logger.log_hyperparams(model_class=type(rfc).__name__)
+    logger.log_hyperparams({'model': rfc.get_params()})
+
+    # Train the model
+    rfc.fit(X_train, y_train.values.ravel())
+    y_pred = rfc.predict(X_test)
+
+    # log the model's performances
+    logger.log_metrics({f'roc_auc_score': round(roc_auc_score(y_test, y_pred), 3)})
+    print(M_MOD_SCORE, round(roc_auc_score(y_test, y_pred), 3))
@@ -0,0 +1,21 @@
+model:
+  bootstrap: true
+  ccp_alpha: 0.0
+  class_weight: null
+  criterion: gini
+  max_depth: null
+  max_features: auto
+  max_leaf_nodes: null
+  max_samples: null
+  min_impurity_decrease: 0.0
+  min_impurity_split: null
+  min_samples_leaf: 1
+  min_samples_split: 2
+  min_weight_fraction_leaf: 0.0
+  n_estimators: 1
+  n_jobs: null
+  oob_score: false
+  random_state: 0
+  verbose: 0
+  warm_start: false
+model_class: RandomForestClassifier