-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexam_mha_mlp_binary_classification.py
More file actions
40 lines (31 loc) · 1.63 KB
/
Copy pathexam_mha_mlp_binary_classification.py
File metadata and controls
40 lines (31 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
# Created by "Thieu" at 21:35, 02/11/2023 ----------%
# Email: nguyenthieu2102@gmail.com %
# Github: https://github.com/thieu1995 %
# --------------------------------------------------%
from sklearn.datasets import load_breast_cancer
from metaperceptron import Data, MhaMlpClassifier
## Load data object
X, y = load_breast_cancer(return_X_y=True)
data = Data(X, y)
## Split train and test
data.split_train_test(test_size=0.2, random_state=2, inplace=True, shuffle=True)
print(data.X_train.shape, data.X_test.shape)
## Scaling dataset
data.X_train, scaler_X = data.scale(data.X_train, scaling_methods=("standard", "minmax"))
data.X_test = scaler_X.transform(data.X_test)
data.y_train, scaler_y = data.encode_label(data.y_train)
data.y_test = scaler_y.transform(data.y_test)
## Create model
print(MhaMlpClassifier.SUPPORTED_CLS_OBJECTIVES)
model = MhaMlpClassifier(hidden_layers=(100,), act_names="ReLU", dropout_rates=None, act_output=None,
optim="BaseGA", optim_params={"name": "WOA", "epoch": 100, "pop_size": 30},
obj_name="F1S", seed=42, verbose=True,
lb=None, ub=None, mode='single', n_workers=None, termination=None)
## Train the model
model.fit(X=data.X_train, y=data.y_train)
## Test the model
y_pred = model.predict(data.X_test)
print(y_pred)
## Calculate some metrics
print(model.evaluate(y_true=data.y_test, y_pred=y_pred, list_metrics=["AS", "F1S", "PS", "FBS"]))