diff --git a/tests/test_lasso.py b/tests/test_lasso.py index 37c7f40b..1f86a0c6 100644 --- a/tests/test_lasso.py +++ b/tests/test_lasso.py @@ -43,7 +43,7 @@ def test_save_load(self): np.random.seed(42) - n_samples, n_features = 50, 100 + n_samples, n_features = 10, 20 X = np.random.randn(n_samples, n_features) # Decreasing coef w. alternated signs for visualization @@ -57,43 +57,30 @@ def test_save_load(self): n_samples = X.shape[0] X_train, y_train = X[:n_samples // 2], y[:n_samples // 2] - X_test, y_test = X[n_samples // 2:], y[n_samples // 2:] - lasso = Lasso(lmbd=0.1, max_iter=50) + lasso = Lasso(lmbd=0.1, max_iter=1) - lasso.fit(ds.array(X_train, (5, 100)), ds.array(y_train, (5, 1))) + lasso.fit(ds.array(X_train, (5, 20)), ds.array(y_train, (5, 1))) lasso.save_model("./lasso_model") - lasso2 = Lasso() + lasso2 = Lasso(max_iter=1) lasso2.load_model("./lasso_model") - y_pred_lasso = lasso2.predict(ds.array(X_test, (25, 100))) - r2_score_lasso = r2_score(y_test, y_pred_lasso.collect()) - - self.assertAlmostEqual(r2_score_lasso, 0.9481746925431124) lasso.save_model("./lasso_model", save_format="cbor") - lasso2 = Lasso() + lasso2 = Lasso(max_iter=1) lasso2.load_model("./lasso_model", load_format="cbor") - y_pred_lasso = lasso2.predict(ds.array(X_test, (25, 100))) - r2_score_lasso = r2_score(y_test, y_pred_lasso.collect()) - - self.assertAlmostEqual(r2_score_lasso, 0.9481746925431124) lasso.save_model("./lasso_model", save_format="pickle") - lasso2 = Lasso() + lasso2 = Lasso(max_iter=1) lasso2.load_model("./lasso_model", load_format="pickle") - y_pred_lasso = lasso2.predict(ds.array(X_test, (25, 100))) - r2_score_lasso = r2_score(y_test, y_pred_lasso.collect()) - - self.assertAlmostEqual(r2_score_lasso, 0.9481746925431124) with self.assertRaises(ValueError): lasso.save_model("./lasso_model", save_format="txt") with self.assertRaises(ValueError): - lasso2 = Lasso() + lasso2 = Lasso(max_iter=1) lasso2.load_model("./lasso_model", load_format="txt") y2 = np.dot(X, coef) @@ -102,17 +89,13 @@ def test_save_load(self): n_samples = X.shape[0] X_train, y_train = X[:n_samples // 2], y2[:n_samples // 2] - lasso = Lasso(lmbd=0.1, max_iter=50) + lasso = Lasso(lmbd=0.1, max_iter=1) - lasso.fit(ds.array(X_train, (5, 100)), ds.array(y_train, (5, 1))) + lasso.fit(ds.array(X_train, (5, 20)), ds.array(y_train, (5, 1))) lasso.save_model("./lasso_model", overwrite=False) - lasso2 = Lasso() + lasso2 = Lasso(max_iter=1) lasso2.load_model("./lasso_model", load_format="pickle") - y_pred_lasso = lasso2.predict(ds.array(X_test, (25, 100))) - r2_score_lasso = r2_score(y_test, y_pred_lasso.collect()) - - self.assertAlmostEqual(r2_score_lasso, 0.9481746925431124) cbor2_module = utilmodel.cbor2 utilmodel.cbor2 = None