Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/mljar/mljar-supervised into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
pplonski committed May 14, 2021
2 parents b787f32 + 74ca9d0 commit d7c6a96
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
Expand Up @@ -5,12 +5,14 @@
import tempfile
import numpy as np
import pandas as pd
from sklearn import datasets
from numpy.testing import assert_almost_equal

from supervised import AutoML
from supervised.exceptions import AutoMLException


class AutoMLReportDirChangeTest(unittest.TestCase):
class AutoMLDirChangeTest(unittest.TestCase):

automl_dir_a = "automl_testing_A"
automl_dir_b = "automl_testing_B"
Expand Down Expand Up @@ -49,3 +51,41 @@ def test_create_report_after_dir_change(self):
results_path=path_b,
)
automl2.report()

def test_compute_predictions_after_dir_change(self):
#
# test for https://github.com/mljar/mljar-supervised/issues/384
#
self.create_dir(self.automl_dir_a)
self.create_dir(self.automl_dir_b)

path_a = os.path.join(self.automl_dir_a, self.automl_dir)
path_b = os.path.join(self.automl_dir_b, self.automl_dir)

X, y = datasets.make_regression(
n_samples=100,
n_features=5,
n_informative=4,
n_targets=1,
shuffle=False,
random_state=0,
)

automl = AutoML(
results_path=path_a,
explain_level=0,
ml_task="regression",
total_time_limit=10,
)
automl.fit(X, y)
p = automl.predict(X[:3])

shutil.move(path_a, path_b)

automl2 = AutoML(
results_path=path_b,
)
p2 = automl2.predict(X[:3])

for i in range(3):
assert_almost_equal(p[i], p2[i])
12 changes: 4 additions & 8 deletions tests/tests_utils/test_metric.py
Expand Up @@ -59,20 +59,16 @@ def test_mape_metric(self):
score = m(y_true, y_predicted)
self.assertEqual(score, 0.0)


def test_user_defined_metric(self):

def custom(x,y,sample_weight=None):
return np.sum(x+y)
def custom(x, y, sample_weight=None):
return np.sum(x + y)

UserDefinedEvalMetric().set_metric(custom)

params = {"name": "user_defined_metric"}
m = Metric(params)

a = np.array([1,1,1])
a = np.array([1, 1, 1])

score = m(a,a)
score = m(a, a)
self.assertEqual(score, 6)


0 comments on commit d7c6a96

Please sign in to comment.