Coder Social home page Coder Social logo

achevrot / svdd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iqiukp/svdd-python

0.0 1.0 0.0 5.79 MB

Python code for abnormal detection or fault detection using Support Vector Data Description (SVDD)

License: MIT License

Python 100.00%

svdd's Introduction

Support Vector Data Description (SVDD)

Python Code for abnormal detection or fault detection using SVDD.

Email: [email protected]


Main features

  • SVDD model for training dataset containing only positive training data. (SVDD)
  • SVDD model for training dataset containing both positive training data and negative training data. (nSVDD)
  • Multiple kinds of kernel functions.
  • Visualization module including ROC curve plotting, test result plotting, and decision boundary.

Requirements

  • matplotlib
  • cvxopt
  • scipy
  • numpy
  • scikit_learn

About SVDD model

Two types of SVDD models are built according to the following references:

[1] Tax D M J, Duin R P W. Support vector data description[J]. Machine learning, 2004, 54(1): 45-66.


A simple application for decision boundary (using differnent kernel functions)


# -*- coding: utf-8 -*-

import sys
sys.path.append("..")
from src.svdd import SVDD
from src.visualize import Visualization as draw
from data import PrepareData as load

# load banana-shape data
trainData, testData, trainLabel, testLabel = load.banana()


# kernel list
kernelList = {"1": {"type": 'gauss', "width": 1/24},
              "2": {"type": 'linear', "offset": 0},
              "3": {"type": 'ploy', "degree": 2, "offset": 0},
              "4": {"type": 'tanh', "gamma": 1e-4, "offset": 0},
              "5": {"type": 'lapl', "width": 1/12}
              }


for i in range(len(kernelList)):

    # set SVDD parameters
    parameters = {"positive penalty": 0.9,
                  "negative penalty": 0.8,
                  "kernel": kernelList.get(str(i+1)),
                  "option": {"display": 'on'}}
    
    # construct an SVDD model
    svdd = SVDD(parameters)
    
    # train SVDD model
    svdd.train(trainData, trainLabel)
      
    # test SVDD model
    distance, accuracy = svdd.test(testData, testLabel)
    
    # visualize the results
    # draw.testResult(svdd, distance)
    # draw.testROC(testLabel, distance)
    draw.boundary(svdd, trainData, trainLabel)

  • gaussian kernel function

  • linear kernel function

  • polynomial kernel function

  • sigmoid kernel function

  • laplacian kernel function

A simple application for abnormal detection or fault detection


# -*- coding: utf-8 -*-

import sys
sys.path.append("..")
from src.svdd import SVDD
from src.visualize import Visualization as draw
from data import PrepareData as load

# load banana-shape data
trainData, testData, trainLabel, testLabel = load.iris()

# set SVDD parameters
parameters = {"positive penalty": 0.9,
              "negative penalty": 0.8,
              "kernel": {"type": 'gauss', "width": 1/24},
              "option": {"display": 'on'}}


# construct an SVDD model
svdd = SVDD(parameters)

# train SVDD model
svdd.train(trainData, trainLabel)


# test SVDD model
distance, accuracy = svdd.test(testData, testLabel)

# visualize the results
draw.testResult(svdd, distance)
draw.testROC(testLabel, distance)

  • test result

  • ROC curve

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.