|
|
|
|
|
|
|
|
|
|
|
import joblib |
|
|
import numpy as np |
|
|
|
|
|
from sklearn.datasets import fetch_openml |
|
|
from sklearn.model_selection import train_test_split |
|
|
from sklearn.metrics import accuracy_score |
|
|
|
|
|
|
|
|
model = joblib.load('isolation_forest.joblib') |
|
|
|
|
|
|
|
|
random_seed = 0 |
|
|
np.random.seed(random_seed) |
|
|
|
|
|
|
|
|
dataset_name = "cardiotocography" |
|
|
dataset = fetch_openml(name=dataset_name, version=1, as_frame=False) |
|
|
X, y = dataset.data, dataset.target |
|
|
s = y == "3" |
|
|
y = s.astype(int) |
|
|
|
|
|
|
|
|
_, X_test, _, y_test = train_test_split(X, y, test_size=0.25, random_state=random_seed) |
|
|
print(f'X_test:\n{X_test[0]}') |
|
|
print(f'y_test:\n{y_test[0]}') |
|
|
|
|
|
|
|
|
y_pred = model.predict(X_test) |
|
|
|
|
|
y_pred = np.where(y_pred == 1, 0, 1) |
|
|
print(f'y_pred:\n{y_pred[0]}') |
|
|
|
|
|
|
|
|
acc = accuracy_score(y_test, y_pred) |
|
|
print(f'Accuracy classification score: {acc}') |
|
|
|