December 2018
Intermediate to advanced
318 pages
8h 28m
English
In this example, we will want to use binary data where 1 will represent a not-normal attack:
from sklearn.model_selection import train_test_splity_binary = y != 'normal.'y_binary.head()
The output can be seen as follows:
Out[43]:0 True 1 True 2 True 3 True 4 True dtype: bool
We divide the data into train and test sets and perform the following actions:
X_train, X_test, y_train, y_test = train_test_split(X, y_binary)y_test.value_counts(normalize=True) # check our null accuracy
The output looks as follows:
True 0.803524 False 0.196476 dtype: float64
On using the isolation forest model, we get this:
model = IsolationForest() model.fit(X_train) # notice that there is no ...
Read now
Unlock full access