|
14 | 14 | import numpy as np |
15 | 15 |
|
16 | 16 |
|
17 | | -MODELS = ["automlx", "autots"] # , "auto", "tods", |
| 17 | +MODELS = ["automlx", "autots"] |
18 | 18 |
|
19 | 19 | # Mandatory YAML parameters |
20 | 20 | TEMPLATE_YAML = { |
@@ -101,7 +101,7 @@ def test_artificial_big(model): |
101 | 101 | assert os.path.exists(f"{output_dirname}/report.html"), "Report not generated." |
102 | 102 |
|
103 | 103 |
|
104 | | -@pytest.mark.parametrize("model", MODELS) |
| 104 | +@pytest.mark.parametrize("model", MODELS + ["auto"]) |
105 | 105 | def test_artificial_small(model): |
106 | 106 | # artificial data |
107 | 107 | d1 = np.random.multivariate_normal( |
@@ -139,6 +139,57 @@ def test_artificial_small(model): |
139 | 139 | assert os.path.exists(f"{output_dirname}/report.html"), "Report not generated." |
140 | 140 |
|
141 | 141 |
|
| 142 | +@pytest.mark.parametrize("model", MODELS) |
| 143 | +def test_validation(model): |
| 144 | + # artificial data |
| 145 | + d1 = np.random.multivariate_normal( |
| 146 | + mean=np.array([-0.5, 0]), cov=np.array([[1, 0], [0, 1]]), size=100 |
| 147 | + ) |
| 148 | + d2 = np.random.multivariate_normal( |
| 149 | + mean=np.array([15, 10]), cov=np.array([[1, 0.3], [0.3, 1]]), size=100 |
| 150 | + ) |
| 151 | + outliers = np.array([[0, 10], [0, 9.5]]) |
| 152 | + d = pd.DataFrame( |
| 153 | + np.concatenate([d1, outliers, d2], axis=0), columns=["val_1", "val_2"] |
| 154 | + ) |
| 155 | + anomaly_col = pd.DataFrame( |
| 156 | + np.concatenate([np.zeros(100), np.ones(2), np.zeros(100)], axis=0), |
| 157 | + columns=["anomaly"], |
| 158 | + ) |
| 159 | + d = d.reset_index().rename({"index": "ds"}, axis=1) |
| 160 | + anomaly_col["ds"] = d["ds"] |
| 161 | + v = d.copy() |
| 162 | + v["anomaly"] = anomaly_col["anomaly"] |
| 163 | + with tempfile.TemporaryDirectory() as tmpdirname: |
| 164 | + anomaly_yaml_filename = f"{tmpdirname}/anomaly.yaml" |
| 165 | + input_data = f"{tmpdirname}/data.csv" |
| 166 | + valid_data = f"{tmpdirname}/valid_data.csv" |
| 167 | + test_data = f"{tmpdirname}/test_data.csv" |
| 168 | + output_dirname = f"{tmpdirname}/results" |
| 169 | + |
| 170 | + d.to_csv(input_data, index=False) |
| 171 | + v.to_csv(valid_data, index=False) |
| 172 | + anomaly_col.to_csv(test_data, index=False) |
| 173 | + |
| 174 | + yaml_i = deepcopy(TEMPLATE_YAML) |
| 175 | + yaml_i["spec"]["model"] = model |
| 176 | + yaml_i["spec"]["input_data"]["url"] = input_data |
| 177 | + yaml_i["spec"]["validation_data"] = {"url": valid_data} |
| 178 | + yaml_i["spec"]["test_data"] = {"url": test_data} |
| 179 | + yaml_i["spec"]["output_directory"]["url"] = output_dirname |
| 180 | + yaml_i["spec"]["contamination"] = 0.05 |
| 181 | + |
| 182 | + with open(anomaly_yaml_filename, "w") as f: |
| 183 | + f.write(yaml.dump(yaml_i)) |
| 184 | + sleep(0.1) |
| 185 | + subprocess.run( |
| 186 | + f"ads operator run -f {anomaly_yaml_filename} --debug", shell=True |
| 187 | + ) |
| 188 | + sleep(0.1) |
| 189 | + subprocess.run(f"ls -a {output_dirname}/", shell=True) |
| 190 | + assert os.path.exists(f"{output_dirname}/report.html"), "Report not generated." |
| 191 | + |
| 192 | + |
142 | 193 | @pytest.mark.parametrize("model, data_dict", parameters_short) |
143 | 194 | def test_load_datasets(model, data_dict): |
144 | 195 | with tempfile.TemporaryDirectory() as tmpdirname: |
|
0 commit comments