Skip to content

Commit

Permalink
Add examples for AutomatedMhaElmComparator class
Browse files Browse the repository at this point in the history
  • Loading branch information
thieu1995 committed Aug 19, 2024
1 parent 9df04e7 commit e7f2bac
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/comparator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python
# Created by "Thieu" at 23:30, 17/08/2024 ----------%
# Email: nguyenthieu2102@gmail.com %
# Github: https://github.com/thieu1995 %
# --------------------------------------------------%
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python
# Created by "Thieu" at 23:30, 17/08/2024 ----------%
# Email: nguyenthieu2102@gmail.com %
# Github: https://github.com/thieu1995 %
# --------------------------------------------------%

from intelelm import get_dataset, AutomatedMhaElmComparator


data = get_dataset("circles")
data.split_train_test(test_size=0.2, random_state=2)
print(data.X_train.shape, data.X_test.shape)

data.X_train, scaler_X = data.scale(data.X_train, scaling_methods=('minmax', ))
data.X_test = scaler_X.transform(data.X_test)

# Example optimizer dict
optimizer_dict = {
'BaseGA': {"epoch": 10, "pop_size": 20},
"OriginalPSO": {"epoch": 10, "pop_size": 20},
}

# Initialize the comparator
compartor = AutomatedMhaElmComparator(
optimizer_dict=optimizer_dict,
task="classification",
hidden_size=10,
act_name="elu",
obj_name="F1S",
verbose=False,
seed=42,
)

# Perform comparison
# results = compartor.compare_cross_val_score(data.X_train, data.y_train, metric="AS", cv=4, n_trials=2, to_csv=True)
# print(results)

# results = compartor.compare_cross_validate(data.X_train, data.y_train, metrics=["AS", "PS", "F1S", "NPV"],
# cv=4, return_train_score=True, n_trials=2, to_csv=True)
# print(results)

results = compartor.compare_train_test(data.X_train, data.y_train, data.X_test, data.y_test, metrics=["AS", "PS", "F1S", "NPV"],
n_trials=2, to_csv=True)
print(results)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python
# Created by "Thieu" at 19:55, 19/08/2024 ----------%
# Email: nguyenthieu2102@gmail.com %
# Github: https://github.com/thieu1995 %
# --------------------------------------------------%

from intelelm import get_dataset, AutomatedMhaElmComparator


data = get_dataset("blobs")
data.split_train_test(test_size=0.2, random_state=2)
print(data.X_train.shape, data.X_test.shape)

data.X_train, scaler_X = data.scale(data.X_train, scaling_methods=('minmax', ))
data.X_test = scaler_X.transform(data.X_test)

# Example optimizer dict
optimizer_dict = {
'BaseGA': {"epoch": 10, "pop_size": 20},
"OriginalPSO": {"epoch": 10, "pop_size": 20},
}

# Initialize the comparator
compartor = AutomatedMhaElmComparator(
optimizer_dict=optimizer_dict,
task="classification",
hidden_size=10,
act_name="elu",
obj_name="F1S",
verbose=True,
seed=42,
)

# Perform comparison
results = compartor.compare_cross_val_score(data.X_train, data.y_train, metric="AS", cv=4, n_trials=2, to_csv=True)
print(results)

# results = compartor.compare_cross_validate(data.X_train, data.y_train, metrics=["AS", "PS", "F1S", "NPV"],
# cv=4, return_train_score=True, n_trials=2, to_csv=True)
# print(results)

# results = compartor.compare_train_test(data.X_train, data.y_train, data.X_test, data.y_test, metrics=["AS", "PS", "F1S", "NPV"],
# n_trials=2, to_csv=True)
# print(results)
49 changes: 49 additions & 0 deletions examples/comparator/exam_automated_mha_elm_regressor_comparator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python
# Created by "Thieu" at 19:59, 19/08/2024 ----------%
# Email: nguyenthieu2102@gmail.com %
# Github: https://github.com/thieu1995 %
# --------------------------------------------------%

import numpy as np
from intelelm import get_dataset, AutomatedMhaElmComparator


data = get_dataset("diabetes")
data.split_train_test(test_size=0.2, random_state=2)
print(data.X_train.shape, data.X_test.shape)

data.X_train, scaler_X = data.scale(data.X_train, scaling_methods=('minmax', ))
data.X_test = scaler_X.transform(data.X_test)

data.y_train, scaler_y = data.scale(data.y_train, scaling_methods=('minmax', ))
data.y_test = scaler_y.transform(np.reshape(data.y_test, (-1, 1)))


# Example optimizer dict
optimizer_dict = {
'BaseGA': {"epoch": 10, "pop_size": 20},
"OriginalPSO": {"epoch": 10, "pop_size": 20},
}

# Initialize the comparator
compartor = AutomatedMhaElmComparator(
optimizer_dict=optimizer_dict,
task="regression",
hidden_size=10,
act_name="elu",
obj_name="R2",
verbose=False,
seed=42,
)

# Perform comparison
# results = compartor.compare_cross_val_score(data.X_train, data.y_train, metric="RMSE", cv=4, n_trials=2, to_csv=True)
# print(results)

# results = compartor.compare_cross_validate(data.X_train, data.y_train, metrics=["MSE", "MAPE", "R2", "KGE", "NSE"],
# cv=4, return_train_score=True, n_trials=2, to_csv=True)
# print(results)

results = compartor.compare_train_test(data.X_train, data.y_train, data.X_test, data.y_test, metrics=["MSE", "MAPE", "R2", "KGE", "NSE"],
n_trials=2, to_csv=True)
print(results)

0 comments on commit e7f2bac

Please sign in to comment.