Skip to content

Commit

Permalink
update tests to cover more
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyangkang committed Oct 26, 2024
1 parent 690ac08 commit d573274
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ def test_AdaSTEMRegressor():
assert np.sum(~np.isnan(pred_mean)) > 0
assert np.sum(~np.isnan(pred_std)) > 0

pred_ = model.predict(X_test, aggregation='median')
assert len(pred_) == len(X_test)
assert np.sum(np.isnan(pred_)) / len(pred_) <= 0.3

pred_return_by_separate_ensembles = model.predict(X_test, return_by_separate_ensembles=True)
assert pred_return_by_separate_ensembles.shape[1]==model.ensemble_fold

pred = model.predict(X_test)
assert len(pred) == len(X_test)
assert np.sum(np.isnan(pred)) / len(pred) <= 0.3
Expand All @@ -171,6 +178,20 @@ def test_AdaSTEMRegressor():
importances_by_points = model.assign_feature_importances_by_points(verbosity=0, n_jobs=1)
assert importances_by_points.shape[0] > 0
assert importances_by_points.shape[1] == len(x_names) + 3

#
eval = AdaSTEM.eval_STEM_res("AAA", pred_df.y_true, pred_df.y_pred) # this should not work
all_nan = True
for eval_metric in eval:
if not np.isnan(eval[eval_metric]):
all_nan = False
break
assert all_nan

# score
score_df = model.score(X_test, y_test)




def test_SphereAdaClassifier():
Expand Down Expand Up @@ -202,10 +223,14 @@ def test_SphereAdaClassifier():
assert importances_by_points.shape[0] > 0
assert importances_by_points.shape[1] == len(x_names) + 3


importances_by_points = model.assign_feature_importances_by_points(verbosity=0, n_jobs=2, aggregation='median')
assert importances_by_points.shape[0] > 0
assert importances_by_points.shape[1] == len(x_names) + 3

def test_parallel_SphereAdaClassifier():
model = make_parallel_SphereAdaClassifier()
model = model.fit(X_train, np.where(y_train > 0, 1, 0))
model = model.set_params(save_gridding_plot=True)

pred_mean, pred_std = model.predict(X_test.reset_index(drop=True), return_std=True, verbosity=1)
assert np.sum(~np.isnan(pred_mean)) > 0
Expand Down Expand Up @@ -261,8 +286,9 @@ def test_SphereAdaSTEMRegressor():
importances_by_points = model.assign_feature_importances_by_points(verbosity=0, n_jobs=1)
assert importances_by_points.shape[0] > 0
assert importances_by_points.shape[1] == len(x_names) + 3


def test_AdaSTEMRegressor():
def test_AdaSTEMRegressor_Hurdle_for_AdaSTEM():
model = make_AdaSTEMRegressor_Hurdle_for_AdaSTEM()
model = model.fit(X_train, np.where(y_train > 0, 1, 0))

Expand All @@ -286,3 +312,33 @@ def test_AdaSTEMRegressor():



# def test_AdaSTEMRegressor_median():
# model = make_AdaSTEMRegressor()
# model = model.fit(X_train, np.where(y_train > 0, 1, 0))

# pred_mean, pred_std = model.predict(X_test.reset_index(drop=True), return_std=True, verbosity=1, n_jobs=1)
# assert np.sum(~np.isnan(pred_mean)) > 0
# assert np.sum(~np.isnan(pred_std)) > 0

# pred = model.predict(X_test)
# assert len(pred) == len(X_test)
# assert np.sum(np.isnan(pred)) / len(pred) <= 0.3

# pred_df = pd.DataFrame(
# {"y_true": y_test.flatten(), "y_pred": np.where(pred.flatten() < 0, 0, pred.flatten())}
# ).dropna()
# assert len(pred_df) > 0

# eval = AdaSTEM.eval_STEM_res("hurdle", pred_df.y_true, pred_df.y_pred)
# assert eval["AUC"] >= 0.5
# assert eval["kappa"] >= 0.2
# assert eval["Spearman_r"] >= 0.2

# model.calculate_feature_importances()
# assert model.feature_importances_.shape[0] > 0

# importances_by_points = model.assign_feature_importances_by_points(verbosity=0, n_jobs=1)
# assert importances_by_points.shape[0] > 0
# assert importances_by_points.shape[1] == len(x_names) + 3


0 comments on commit d573274

Please sign in to comment.