From e050d21d2f6ffb5e1d6f0f5487fd0eb4a4e5d79a Mon Sep 17 00:00:00 2001 From: Aydin Abedinia Date: Sat, 20 Jul 2024 16:48:52 +0330 Subject: [PATCH] minor change on printing result and version 0.0.2 --- semicart/semicart.py | 31 +++++++++++++++++-------------- setup.py | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/semicart/semicart.py b/semicart/semicart.py index bc4bae3..3f4f251 100644 --- a/semicart/semicart.py +++ b/semicart/semicart.py @@ -167,24 +167,27 @@ def _entropy_calculate_information_gain(self, y, y_left, y_right, weights, weigh return info_gain -def tuning_params(X_train, X_test, y_train, y_test, neighbors) -> dict: +def tuning_params(x_train, x_test, y_train, y_test, neighbors) -> dict: result = {} strategies = ["ENTROPY", "GINI"] best_score = 0 - if neighbors is None: - neighbors = [1, 2, 3, 4, 5] - def max_score(result): - return max(result["accuracy_score"], result["precision_score"], result["recall_score"], result["f1_score"]) + def max_score(result_value): + return max( + result_value["accuracy_score"], + result_value["precision_score"], + result_value["recall_score"], + result_value["f1_score"] + ) for n in tqdm(neighbors, desc="Neighbors"): weights_calculator = WeightCalculator() - weights = weights_calculator.calculate_weights_nn(X_train, X_test, n) + weights = weights_calculator.calculate_weights_nn(x_train, x_test, n) - for strategy_param in tqdm(strategies, desc="Strategies"): + for strategy_param in strategies: tree = SemiCARTClassifier(weights, strategy=strategy_param) - tree.fit(X_train, y_train) - y_pred = tree.predict(X_test) + tree.fit(x_train, y_train) + y_pred = tree.predict(x_test) result["knn"] = { "method": strategy_param, @@ -200,11 +203,11 @@ def max_score(result): best_result = result["knn"] print(f"New best result: {best_result}") - for measure in tqdm(weights_calculator.get_measurements(), desc="distance measurements"): - weights = weights_calculator.calculate_weights_dist(X_train, X_test, n, measure) + for measure in weights_calculator.get_measurements(): + weights = weights_calculator.calculate_weights_dist(x_train, x_test, n, measure) tree = SemiCARTClassifier(weights, strategy_param) - tree.fit(X_train, y_train) - y_pred = tree.predict(X_test) + tree.fit(x_train, y_train) + y_pred = tree.predict(x_test) result[measure] = { "method": strategy_param, @@ -218,6 +221,6 @@ def max_score(result): if max_score(result[measure]) > best_score: best_score = max_score(result[measure]) best_result = result[measure] - print(f"New best result: {best_result}") + print(f"New best result: {measure} {best_result}") return result diff --git a/setup.py b/setup.py index f044a8c..d527011 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="semicart", - version="0.0.1", + version="0.0.2", author="Aydin Abedinia", author_email="abedinia.aydin@gmail.com", description="Building semi-supervised decision trees with semi-cart algorithm",