Anomaly Detection-1
Anomaly Detection-1
Anomaly Detection -1
Isolation Forest 0
Complete Theory
0
Code Implementation
50
Va t
lu e n
_free C o nte
iwmduvk9p
[1]: 0 1
0 1.616671 1.944522
1 1.256461 1.609444
2 -2.343919 4.392961
[2]: # now plot the data points into the scater plot
import matplotlib.pyplot as plt
plt.scatter(df.iloc[:,0], df.iloc[:,1])
1
[3]: # importing the Isolation forest from sklearn
import warnings
warnings.filterwarnings('ignore')
from sklearn.ensemble import IsolationForest
prediction = clf.predict(df)
[5]: array([ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1,
1, 1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1,
1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1,
-1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1,
-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1,
1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1,
2
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1,
-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1,
-1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1])
[6]: (array([ 20, 24, 45, 48, 53, 55, 63, 72, 74, 78, 83, 85, 87,
92, 97, 108, 114, 119, 130, 133, 141, 151, 167, 179, 187, 199,
212, 217, 220, 221, 227, 242, 247, 248]),)
3
2 Observation:
The data points in red color are actually Outliers that we get by Anomaly detection technique.
this red points here represent those persons who having disease in our dataset.
[ ]:
[ ]:
[ ]: