GithubHelp home page GithubHelp logo

adityajn105 / svm-from-scratch Goto Github PK

View Code? Open in Web Editor NEW
47.0 5.0 41.0 21 KB

An Implementation of SVM - Support Vector Machines using Linear Kernel. This is just for understanding of SVM and its algorithm.

Jupyter Notebook 100.00%
svm svm-classifier machine-learning-algorithms

svm-from-scratch's Introduction

Implemeting SVM from scratch using Python

  1. Refrence

  2. About SVM (General required for algo)

    • For all xi in training Data:
      •  xi.w + b <= -1   if yi = -1 (belongs to -ve class)
         xi.w + b >= +1	if yi = +1 (belongs to +ve class)
         			or
          	__yi(xi.w+b) >= 1__
        
    • for all support vectors(SV) (data points which decides margin)
      •   xi.w+b = -1    here xi is -ve SV and yi is -1
          xi.w+b = +1    here xi is +ve SV and yi is +1
        
    • For decision Boundary yi(xi.w+b)=0 here xi belongs to point in decision boundary
    • Our Objective is to maximize Width W
      • W = ((X+ - X-).w)/|w|
      • or we can say minimize |w|
    • Once we have found optimized w and b using algorithm
      • x.w+b = 1 is line passing through +ve support vectors
      • x.w+b = -1 is line passing through -ve support vectors
      • x.w+b = 0 is decision boundary
    • It is not necessary that support vector lines always pass through support vectors
    • It is a Convex Optimization problem and will always lead to a global minimum
    • This is Linear SVM means kernel is linear
  3. Algorithm in Code (See code for better understanding)

    1. Start with random big value of w say(w0,w0) we will decrease it later
    2. Select step size as w0*0.1
    3. A small value of b, we will increase it later
      • b will range from (-b0 < b < +b0, step = step*b_multiple)
      • This is also computational expensive. So select b0 wisely
    4. We will check for points xi in dataset:
      • Check will for all transformation of w like (w0,w0), (-w0,w0), (w0,-w0), (-w0,-w0)
      • if not yi(xi.w+b)>=1 for all points then break
      • Else find |w| and put it in dictionary as key and (w,b) as values
      • If w<=0 then current step have been completed and go to step 6
      • Else decrease w as (w0-step,w0-step) and continue with step 3
    5. Do this step until step becomes w0*0.001 because futher it will be point of expense
      • step = step*0.1
      • go to step 3
    6. Select (w,b) which has min |w| form the dictionary

svm-from-scratch's People

Contributors

adityajn105 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  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.