Spaces:
Sleeping
Sleeping
Amol Kaushik commited on
Commit ·
a670874
1
Parent(s): 1857bb8
testing updates to rasa's
Browse files- A4/conftest.py +15 -3
- A4/models/champion_model_final_2.pkl +0 -3
- A4/models/final_champion_model_A3.pkl +0 -3
- A4/test_models.py +19 -6
A4/conftest.py
CHANGED
|
@@ -17,14 +17,19 @@ def models_dir(repo_root):
|
|
| 17 |
return os.path.join(repo_root, "A3", "models")
|
| 18 |
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
@pytest.fixture
|
| 21 |
def regression_model_path(models_dir):
|
| 22 |
return os.path.join(models_dir, "champion_model_final_2.pkl")
|
| 23 |
|
| 24 |
|
| 25 |
@pytest.fixture
|
| 26 |
-
def classification_model_path(
|
| 27 |
-
return os.path.join(
|
| 28 |
|
| 29 |
|
| 30 |
@pytest.fixture
|
|
@@ -79,4 +84,11 @@ def sample_classification_features(classification_artifact):
|
|
| 79 |
# expected values
|
| 80 |
@pytest.fixture
|
| 81 |
def expected_classification_classes():
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
return os.path.join(repo_root, "A3", "models")
|
| 18 |
|
| 19 |
|
| 20 |
+
@pytest.fixture
|
| 21 |
+
def a4_models_dir(repo_root):
|
| 22 |
+
return os.path.join(repo_root, "A4", "models")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
@pytest.fixture
|
| 26 |
def regression_model_path(models_dir):
|
| 27 |
return os.path.join(models_dir, "champion_model_final_2.pkl")
|
| 28 |
|
| 29 |
|
| 30 |
@pytest.fixture
|
| 31 |
+
def classification_model_path(a4_models_dir):
|
| 32 |
+
return os.path.join(a4_models_dir, "weaklink_classifier_rf.pkl")
|
| 33 |
|
| 34 |
|
| 35 |
@pytest.fixture
|
|
|
|
| 84 |
# expected values
|
| 85 |
@pytest.fixture
|
| 86 |
def expected_classification_classes():
|
| 87 |
+
# all 14 weaklink categories
|
| 88 |
+
return [
|
| 89 |
+
'ExcessiveForwardLean', 'ForwardHead', 'LeftArmFallForward',
|
| 90 |
+
'LeftAsymmetricalWeightShift', 'LeftHeelRises', 'LeftKneeMovesInward',
|
| 91 |
+
'LeftKneeMovesOutward', 'LeftShoulderElevation', 'RightArmFallForward',
|
| 92 |
+
'RightAsymmetricalWeightShift', 'RightHeelRises', 'RightKneeMovesInward',
|
| 93 |
+
'RightKneeMovesOutward', 'RightShoulderElevation'
|
| 94 |
+
]
|
A4/models/champion_model_final_2.pkl
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:2aa2439a4b32f522de5f0cef2f5267d02c39f14a36fdbcbfb08273cfa7fd6178
|
| 3 |
-
size 9202
|
|
|
|
|
|
|
|
|
|
|
|
A4/models/final_champion_model_A3.pkl
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:29b0e9b7f4f950904687023290cc0e5e044426f821778ed3d220bba708621716
|
| 3 |
-
size 563557
|
|
|
|
|
|
|
|
|
|
|
|
A4/test_models.py
CHANGED
|
@@ -76,7 +76,8 @@ class TestClassificationModelLoading:
|
|
| 76 |
assert "feature_columns" in classification_artifact
|
| 77 |
|
| 78 |
def test_classification_artifact_has_classes(self, classification_artifact):
|
| 79 |
-
|
|
|
|
| 80 |
|
| 81 |
def test_classification_model_has_predict_method(self, classification_artifact):
|
| 82 |
model = classification_artifact["model"]
|
|
@@ -85,7 +86,7 @@ class TestClassificationModelLoading:
|
|
| 85 |
def test_classification_classes_match_expected(
|
| 86 |
self, classification_artifact, expected_classification_classes
|
| 87 |
):
|
| 88 |
-
classes = list(classification_artifact["
|
| 89 |
assert sorted(classes) == sorted(expected_classification_classes)
|
| 90 |
|
| 91 |
|
|
@@ -95,7 +96,11 @@ class TestClassificationModelPrediction:
|
|
| 95 |
self, classification_artifact, sample_classification_features
|
| 96 |
):
|
| 97 |
model = classification_artifact["model"]
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
assert isinstance(prediction, np.ndarray)
|
| 100 |
|
| 101 |
def test_classification_prediction_shape(
|
|
@@ -103,7 +108,11 @@ class TestClassificationModelPrediction:
|
|
| 103 |
):
|
| 104 |
# one class per sample
|
| 105 |
model = classification_artifact["model"]
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
assert prediction.shape[0] == len(sample_classification_features)
|
| 108 |
|
| 109 |
def test_classification_prediction_is_valid_class(
|
|
@@ -112,7 +121,11 @@ class TestClassificationModelPrediction:
|
|
| 112 |
):
|
| 113 |
# should be a valid class
|
| 114 |
model = classification_artifact["model"]
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
assert prediction in expected_classification_classes
|
| 117 |
|
| 118 |
|
|
@@ -122,7 +135,7 @@ class TestModelArtifactStructure:
|
|
| 122 |
assert "test_metrics" in regression_artifact
|
| 123 |
|
| 124 |
def test_classification_artifact_has_metrics(self, classification_artifact):
|
| 125 |
-
assert "
|
| 126 |
|
| 127 |
def test_regression_metrics_has_r2(self, regression_artifact):
|
| 128 |
metrics = regression_artifact.get("test_metrics", {})
|
|
|
|
| 76 |
assert "feature_columns" in classification_artifact
|
| 77 |
|
| 78 |
def test_classification_artifact_has_classes(self, classification_artifact):
|
| 79 |
+
# weaklink categories for the 14 classes
|
| 80 |
+
assert "weaklink_categories" in classification_artifact
|
| 81 |
|
| 82 |
def test_classification_model_has_predict_method(self, classification_artifact):
|
| 83 |
model = classification_artifact["model"]
|
|
|
|
| 86 |
def test_classification_classes_match_expected(
|
| 87 |
self, classification_artifact, expected_classification_classes
|
| 88 |
):
|
| 89 |
+
classes = list(classification_artifact["weaklink_categories"])
|
| 90 |
assert sorted(classes) == sorted(expected_classification_classes)
|
| 91 |
|
| 92 |
|
|
|
|
| 96 |
self, classification_artifact, sample_classification_features
|
| 97 |
):
|
| 98 |
model = classification_artifact["model"]
|
| 99 |
+
scaler = classification_artifact.get("scaler")
|
| 100 |
+
features = sample_classification_features
|
| 101 |
+
if scaler is not None:
|
| 102 |
+
features = scaler.transform(features)
|
| 103 |
+
prediction = model.predict(features)
|
| 104 |
assert isinstance(prediction, np.ndarray)
|
| 105 |
|
| 106 |
def test_classification_prediction_shape(
|
|
|
|
| 108 |
):
|
| 109 |
# one class per sample
|
| 110 |
model = classification_artifact["model"]
|
| 111 |
+
scaler = classification_artifact.get("scaler")
|
| 112 |
+
features = sample_classification_features
|
| 113 |
+
if scaler is not None:
|
| 114 |
+
features = scaler.transform(features)
|
| 115 |
+
prediction = model.predict(features)
|
| 116 |
assert prediction.shape[0] == len(sample_classification_features)
|
| 117 |
|
| 118 |
def test_classification_prediction_is_valid_class(
|
|
|
|
| 121 |
):
|
| 122 |
# should be a valid class
|
| 123 |
model = classification_artifact["model"]
|
| 124 |
+
scaler = classification_artifact.get("scaler")
|
| 125 |
+
features = sample_classification_features
|
| 126 |
+
if scaler is not None:
|
| 127 |
+
features = scaler.transform(features)
|
| 128 |
+
prediction = model.predict(features)[0]
|
| 129 |
assert prediction in expected_classification_classes
|
| 130 |
|
| 131 |
|
|
|
|
| 135 |
assert "test_metrics" in regression_artifact
|
| 136 |
|
| 137 |
def test_classification_artifact_has_metrics(self, classification_artifact):
|
| 138 |
+
assert "test_performance" in classification_artifact
|
| 139 |
|
| 140 |
def test_regression_metrics_has_r2(self, regression_artifact):
|
| 141 |
metrics = regression_artifact.get("test_metrics", {})
|