目标:使用PyOD库生成toy example并调用HBOS
- 使用pyod库生成toy example
官网上给出的代码为见pyod官网详细参数描述
pyod.utils.data.generate_data(n_train=1000, n_test=500, n_features=2, contamination=0.1, train_only=False, offset=10, behaviour='old', random_state=None)[source]
正态数据由多元高斯分布生成,离群值由均匀分布生成。返回值为
X_train (numpy array of shape (n_train, n_features)) – Training data.
y_train (numpy array of shape (n_train,)) – Training ground truth.
X_test (numpy array of shape (n_test, n_features)) – Test data.
y_test (numpy array of shape (n_test,)) – Test ground truth.
打印出来:
画图展示:
import numpy as np
import matplotlib.pyplot as plt
import pyod as py
dt=py.utils.data.generate_data(
n_train=1000, n_test=500, n_features=2, contamination=0.1,
train_only=False, offset=10, behaviour='old', random_state=None)
#对数据进行拆分
x_train=dt[0]
y_train=dt[1]
x_test=dt[2]
y_test=dt[3]
print(x_train)
print(y_train)
print(x_test)
F1=x_train[:,[0]].