-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexam_multiclass_classification.py
More file actions
37 lines (28 loc) · 1.34 KB
/
Copy pathexam_multiclass_classification.py
File metadata and controls
37 lines (28 loc) · 1.34 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
#!/usr/bin/env python
# Created by "Thieu" at 13:48, 16/05/2025 ----------%
# Email: nguyenthieu2102@gmail.com %
# Github: https://github.com/thieu1995 %
# --------------------------------------------------%
from sklearn.datasets import load_iris
from pylwl import Data, LwClassifier
## Load data object
X, y = load_iris(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)
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)
## Train and test
model = LwClassifier(kernel="gaussian", tau=1.0)
model.fit(data.X_train, data.y_train)
## Predict
print("Predicted:", model.predict(data.X_test))
print("Probabilities:\n", model.predict_proba(data.X_test))
## Calculate some metrics
print(model.score(X=data.X_test, y=data.y_test))
print(model.scores(X=data.X_test, y=data.y_test, list_metrics=["PS", "RS", "NPV", "F1S", "F2S"]))
print(model.evaluate(y_true=data.y_test, y_pred=model.predict(data.X_test), list_metrics=["F2S", "CKS", "FBS"]))