Download tests/test_model.py from devrup404/SignalMod: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/devrup404/SignalMod/resolve/7e7e06acfc596420cd43256bcf773e93d5aa334f/tests/test_model.py
- Command line
-
hf download hf://spaces/devrup404/SignalMod@7e7e06acfc596420cd43256bcf773e93d5aa334f/tests/test_model.py
-
curl -L -o test_model.py https://huggingface.co/spaces/devrup404/SignalMod/resolve/7e7e06acfc596420cd43256bcf773e93d5aa334f/tests/test_model.py
1.23 kB
| """Tests de salida binaria de modelos sklearn.""" | |
| import numpy as np | |
| import pytest | |
| from src.models.baseline import build_model | |
| X_TRAIN = [ | |
| "the quick brown fox is nice", | |
| "the lazy dog sleeps well", | |
| "the fox and dog are friends", | |
| "another calm peaceful day today", | |
| "you are stupid and worthless idiot", | |
| "kill them all right now attack", | |
| ] | |
| Y_TRAIN = [0, 0, 0, 0, 1, 1] | |
| X_PRED = ["the fox is calm", "you idiot fool"] | |
| def trained_lr(models_config: str, features_config: str, best_params_config: str): | |
| model = build_model( | |
| "lr", | |
| config_path=models_config, | |
| feat_config_path=features_config, | |
| best_params_path=best_params_config, | |
| ) | |
| model.fit(X_TRAIN, Y_TRAIN) | |
| return model | |
| def test_predict_binary_labels(trained_lr): | |
| preds = trained_lr.predict(X_PRED) | |
| assert preds.shape == (len(X_PRED),) | |
| assert set(np.unique(preds)).issubset({0, 1}) | |
| def test_predict_proba_valid_binary_distribution(trained_lr): | |
| proba = trained_lr.predict_proba(X_PRED) | |
| assert proba.shape == (len(X_PRED), 2) | |
| assert np.all(proba >= 0.0) | |
| assert np.all(proba <= 1.0) | |
| np.testing.assert_allclose(proba.sum(axis=1), 1.0, rtol=1e-5) | |