Reem commited on
Commit
5437e78
Β·
1 Parent(s): 3e20c68

safe-dep-test?

Browse files
Files changed (5) hide show
  1. A4/test_models.py +9 -5
  2. A5/final_report_A5.ipynb +1 -1
  3. Untitled.ipynb +107 -0
  4. app.py +2 -2
  5. requirements.txt +2 -0
A4/test_models.py CHANGED
@@ -79,9 +79,10 @@ class TestClassificationModelLoading:
79
  def test_classification_artifact_has_feature_columns(self, classification_artifact):
80
  assert "feature_columns" in classification_artifact
81
 
82
- def test_classification_artifact_has_classes(self, classification_artifact):
83
- # weaklink categories for the 14 classes
84
- assert "weaklink_categories" in classification_artifact
 
85
 
86
  def test_classification_model_has_predict_method(self, classification_artifact):
87
  model = classification_artifact["model"]
@@ -90,8 +91,10 @@ class TestClassificationModelLoading:
90
  def test_classification_classes_match_expected(
91
  self, classification_artifact, expected_classification_classes
92
  ):
93
- classes = list(classification_artifact["weaklink_categories"])
 
94
  assert sorted(classes) == sorted(expected_classification_classes)
 
95
 
96
 
97
  class TestClassificationModelPrediction:
@@ -138,8 +141,9 @@ class TestModelArtifactStructure:
138
  def test_regression_artifact_has_metrics(self, regression_artifact):
139
  assert "test_metrics" in regression_artifact
140
 
 
141
  def test_classification_artifact_has_metrics(self, classification_artifact):
142
- assert "test_performance" in classification_artifact
143
 
144
  def test_regression_metrics_has_r2(self, regression_artifact):
145
  metrics = regression_artifact.get("test_metrics", {})
 
79
  def test_classification_artifact_has_feature_columns(self, classification_artifact):
80
  assert "feature_columns" in classification_artifact
81
 
82
+
83
+ def test_classification_model_has_classes(self, classification_artifact):
84
+ model = classification_artifact["model"]
85
+ assert hasattr(model, "classes_")
86
 
87
  def test_classification_model_has_predict_method(self, classification_artifact):
88
  model = classification_artifact["model"]
 
91
  def test_classification_classes_match_expected(
92
  self, classification_artifact, expected_classification_classes
93
  ):
94
+
95
+ classes = list(classification_artifact["model"].classes_)
96
  assert sorted(classes) == sorted(expected_classification_classes)
97
+
98
 
99
 
100
  class TestClassificationModelPrediction:
 
141
  def test_regression_artifact_has_metrics(self, regression_artifact):
142
  assert "test_metrics" in regression_artifact
143
 
144
+
145
  def test_classification_artifact_has_metrics(self, classification_artifact):
146
+ assert "test_metrics" in classification_artifact
147
 
148
  def test_regression_metrics_has_r2(self, regression_artifact):
149
  metrics = regression_artifact.get("test_metrics", {})
A5/final_report_A5.ipynb CHANGED
@@ -252,7 +252,7 @@
252
  "name": "python",
253
  "nbconvert_exporter": "python",
254
  "pygments_lexer": "ipython3",
255
- "version": "3.12.3"
256
  }
257
  },
258
  "nbformat": 4,
 
252
  "name": "python",
253
  "nbconvert_exporter": "python",
254
  "pygments_lexer": "ipython3",
255
+ "version": "3.12.8"
256
  }
257
  },
258
  "nbformat": 4,
Untitled.ipynb ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 7,
6
+ "id": "6de1a7e2-d47b-4de4-a006-882bc270d9d3",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "ename": "ModuleNotFoundError",
11
+ "evalue": "No module named 'xgboost'",
12
+ "output_type": "error",
13
+ "traceback": [
14
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
15
+ "\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
16
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[7]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mA5\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mCorrelationFilter\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m CorrelationFilter\n\u001b[32m 2\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpickle\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mxgboost\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mxgb\u001b[39;00m\n\u001b[32m 4\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mlightgbm\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mlgb\u001b[39;00m\n\u001b[32m 5\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mA5/models/ensemble_classification_champion.pkl\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mrb\u001b[39m\u001b[33m\"\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m f:\n",
17
+ "\u001b[31mModuleNotFoundError\u001b[39m: No module named 'xgboost'"
18
+ ]
19
+ }
20
+ ],
21
+ "source": []
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 8,
26
+ "id": "dff0f7ab-3b6e-4299-a61e-bb49a895167f",
27
+ "metadata": {},
28
+ "outputs": [
29
+ {
30
+ "name": "stdout",
31
+ "output_type": "stream",
32
+ "text": [
33
+ "Collecting xgboost\n",
34
+ " Downloading xgboost-3.2.0-py3-none-macosx_12_0_arm64.whl.metadata (2.1 kB)\n",
35
+ "Collecting lightgbm\n",
36
+ " Downloading lightgbm-4.6.0-py3-none-macosx_12_0_arm64.whl.metadata (17 kB)\n",
37
+ "Requirement already satisfied: numpy in /Users/reemothman/miniconda3/lib/python3.12/site-packages (from xgboost) (1.26.4)\n",
38
+ "Requirement already satisfied: scipy in /Users/reemothman/miniconda3/lib/python3.12/site-packages (from xgboost) (1.17.0)\n",
39
+ "Downloading xgboost-3.2.0-py3-none-macosx_12_0_arm64.whl (2.3 MB)\n",
40
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.3/2.3 MB\u001b[0m \u001b[31m23.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
41
+ "\u001b[?25hDownloading lightgbm-4.6.0-py3-none-macosx_12_0_arm64.whl (1.6 MB)\n",
42
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.6/1.6 MB\u001b[0m \u001b[31m26.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
43
+ "\u001b[?25hInstalling collected packages: xgboost, lightgbm\n",
44
+ "Successfully installed lightgbm-4.6.0 xgboost-3.2.0\n"
45
+ ]
46
+ }
47
+ ],
48
+ "source": [
49
+ "!pip install xgboost lightgbm"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": 9,
55
+ "id": "d93e2239-29aa-434e-a82f-cc00cde6064a",
56
+ "metadata": {},
57
+ "outputs": [
58
+ {
59
+ "name": "stdout",
60
+ "output_type": "stream",
61
+ "text": [
62
+ "dict_keys(['model', 'model_name', 'scaler', 'feature_columns', 'cv_metrics', 'test_metrics', 'a4_champion_f1', 'improvement_pct'])\n"
63
+ ]
64
+ }
65
+ ],
66
+ "source": [
67
+ "from A5.CorrelationFilter import CorrelationFilter\n",
68
+ "import pickle\n",
69
+ "import xgboost as xgb\n",
70
+ "import lightgbm as lgb\n",
71
+ "with open(\"A5/models/ensemble_classification_champion.pkl\", \"rb\") as f:\n",
72
+ " artifact = pickle.load(f)\n",
73
+ "\n",
74
+ "print(artifact.keys())"
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "execution_count": null,
80
+ "id": "b96efe6a-86f0-4e45-94ed-98ff1da1b8e9",
81
+ "metadata": {},
82
+ "outputs": [],
83
+ "source": []
84
+ }
85
+ ],
86
+ "metadata": {
87
+ "kernelspec": {
88
+ "display_name": "Python 3 (ipykernel)",
89
+ "language": "python",
90
+ "name": "python3"
91
+ },
92
+ "language_info": {
93
+ "codemirror_mode": {
94
+ "name": "ipython",
95
+ "version": 3
96
+ },
97
+ "file_extension": ".py",
98
+ "mimetype": "text/x-python",
99
+ "name": "python",
100
+ "nbconvert_exporter": "python",
101
+ "pygments_lexer": "ipython3",
102
+ "version": "3.12.8"
103
+ }
104
+ },
105
+ "nbformat": 4,
106
+ "nbformat_minor": 5
107
+ }
app.py CHANGED
@@ -15,8 +15,8 @@ MODEL_PATH = os.path.join(
15
  )
16
  CLASSIFICATION_MODEL_PATH = os.path.join(
17
  SCRIPT_DIR,
18
- "A4/models/weaklink_classifier_rf.pkl",
19
- # new classifier without "classes" key "A5/models/weaklink_classifier_rfc_A4.pkl"
20
  )
21
  DATA_PATH = os.path.join(
22
  SCRIPT_DIR,
 
15
  )
16
  CLASSIFICATION_MODEL_PATH = os.path.join(
17
  SCRIPT_DIR,
18
+ "A5b/models/ensemble_classification_champion.pkl",
19
+ # new classifier without "classes" key "A5b/models/ensemble_classification_champion.pkl"
20
  )
21
  DATA_PATH = os.path.join(
22
  SCRIPT_DIR,
requirements.txt CHANGED
@@ -5,6 +5,8 @@ scikit-learn==1.8.0
5
  statsmodels==0.14.4
6
  matplotlib==3.9.2
7
  gdown==5.2.0
 
 
8
 
9
  pytest==8.3.4
10
  pytest-cov==6.0.0
 
5
  statsmodels==0.14.4
6
  matplotlib==3.9.2
7
  gdown==5.2.0
8
+ xgboost==3.2.0
9
+ lightgbm==4.6.0
10
 
11
  pytest==8.3.4
12
  pytest-cov==6.0.0