Coder Social home page Coder Social logo

outlierdetection's Introduction

OutlierDetection

Load the dataset

from sklearn.datasets import load_diabetes a = load_diabetes() X = a.data

Import the required libraries

from sklearn.ensemble import IsolationForest

clf = IsolationForest(n_estimators=100, contamination=0.1, random_state=42) clf.fit(X)

y_pred = clf.predict(X)

import matplotlib.pyplot as plt

plt.scatter(X[:, 0], X[:, 1], c=y_pred, cmap='viridis') plt.title("Isolation Forest Outlier Detection on DIABETES Dataset") plt.xlabel("Sepal Length") plt.ylabel("Sepal Width") plt.show()

4

from sklearn.neighbors import LocalOutlierFactor

clf = LocalOutlierFactor(n_neighbors=20, contamination=0.1) y_pred = clf.fit_predict(X)

plt.scatter(X[:, 0], X[:, 1], c=y_pred, cmap='viridis') plt.title("Local Outlier Factor Outlier Detection on DIABETES Dataset") plt.xlabel("Sepal Length") plt.ylabel("Sepal Width") plt.show()

5

import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import load_iris from sklearn.ensemble import IsolationForest from sklearn.neighbors import LocalOutlierFactor

Load the IRIS dataset

a = load_diabetes() X = a.data y = a.target

Fit Isolation Forest model

clf_iso = IsolationForest(contamination=0.1, random_state=42) y_pred_iso = clf_iso.fit_predict(X)

Fit Local Outlier Factor model

clf_lof = LocalOutlierFactor(contamination=0.1) y_pred_lof = clf_lof.fit_predict(X)

Plot Isolation Forest outliers

plt.scatter(X[:, 0], X[:, 1], c=np.where(y_pred_iso == -1, 'red', 'blue'), label='Isolation Forest') plt.title("Outlier Detection using Isolation Forest on DIABETES Dataset") plt.xlabel("Sepal Length") plt.ylabel("Sepal Width") plt.legend() plt.show()

6

Plot Local Outlier Factor outliers

plt.scatter(X[:, 0], X[:, 1], c=np.where(y_pred_lof == -1, 'red', 'blue'), label='Local Outlier Factor') plt.title("Outlier Detection using Local Outlier Factor on DIABETES Dataset") plt.xlabel("Sepal Length") plt.ylabel("Sepal Width") plt.legend() plt.show()

7

outlierdetection's People

Contributors

rakshureddy1308 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.