from pyod.utils.data import generate_data,evaluate_print
X_train, y_train, X_test, y_test = generate_data(n_train=200, n_test=100, contamination=0.1)
X_train.shape
(200, 2)
X_test.shape
(100, 2)
from pyod.models import hbos
from pyod.utils.example import visualize
clf = hbos.HBOS()
clf.fit(X_train)
y_train_pred = clf.labels_
y_train_socres = clf.decision_scores_
y_test_pred = clf.predict(X_test)
y_test_scores = clf.decision_function(X_test)
print(y_test_pred)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
print(y_test_scores)
array([1.94607743, 1.94607743, 1.94607743, 3.18758465, 2.99449223,
1.94607743, 3.18758465, 2.99449223, 1.94607743, 3.18758465,
1.94607743, 1.94607743, 3.18758465, 1.94607743, 1.94607743,
1.94607743, 3.18758465, 1.94607743, 2.99449223, 1.94607743,
1.94607743, 1.94607743, 1.94607743, 3.18758465, 3.18758465,
2.99449223, 1.94607743, 1.94607743, 1.94607743, 3.18758465,
1.94607743, 2.99449223, 1.94607743, 1.94607743, 1.94607743,
1.94607743, 2.99449223, 1.94607743, 1.94607743, 1.94607743,
1.94607743, 1.94607743, 3.18758465, 1.94607743, 1.94607743,
2.99449223, 2.99449223, 3.18758465, 2.99449223, 1.94607743,
1.94607743, 1.94607743, 1.94607743, 1.94607743, 3.18758465,
1.94607743, 3.18758465, 3.18758465, 1.94607743, 1.94607743,
1.94607743, 2.99449223, 3.18758465, 2.99449223, 1.94607743,
1.94607743, 3.18758465, 1.94607743, 1.94607743, 1.94607743,
1.94607743, 1.94607743, 1.94607743, 2.99449223, 1.94607743,
2.99449223, 1.94607743, 3.18758465, 3.18758465, 1.94607743,
2.99449223, 2.99449223, 1.94607743, 1.94607743, 1.94607743,
1.94607743, 2.99449223, 1.94607743, 3.18758465, 1.94607743,
6.36222028, 6.47923046, 6.5608128 , 6.52101746, 6.36222028,
6.52015473, 6.44010653, 5.30002108, 6.47923046, 6.51944504])
clf_name = 'HBOS'
evaluate_print(clf_name, y_test, y_test_scores)
HBOS ROC:1.0, precision @ rank n:1.0
visualize(clf_name,
X_train, y_train,
X_test, y_test,
y_train_pred,y_test_pred,
show_figure=True,
save_figure=False
)