Created
July 9, 2020 07:49
-
-
Save gautamdudeja90/990d0a675557a2484b4b0d365a260491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isolation_forest = IsolationForest(n_estimators=100) | |
isolation_forest.fit(df['Sales'].values.reshape(-1, 1)) | |
xx = np.linspace(df['Sales'].min(), df['Sales'].max(), len(df)).reshape(-1,1) | |
anomaly_score = isolation_forest.decision_function(xx) | |
outlier = isolation_forest.predict(xx) | |
plt.figure(figsize=(10,4)) | |
plt.plot(xx, anomaly_score, label='anomaly score') | |
plt.fill_between(xx.T[0], np.min(anomaly_score), np.max(anomaly_score), | |
where=outlier==-1, color='r', | |
alpha=.4, label='outlier region') | |
plt.legend() | |
plt.ylabel('anomaly score') | |
plt.xlabel('Sales') | |
plt.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment