Skip to content

Commit

Permalink
minor change on printing result and version 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
abedinia committed Jul 20, 2024
1 parent 7885354 commit e050d21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions semicart/semicart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e050d21

Please sign in to comment.