GithubHelp home page GithubHelp logo

tf-svm's Introduction

Tensorflow Linear SVM

A demonstration of how you can use TensorFlow to implement a standard L2-regularized support vector machine (SVM) in primal form.

linear_svm.py optimizes the following SVM cost using gradient descent:

where

The first part of the cost function, i.e. the regularization part, is implemented by the regularization_loss expression, and the second part is implemented by the hinge_loss expression in the code.

Run the code using

python linear_svm.py --train linearly_separable_data.csv --svmC 1 --verbose True --num_epochs 10

On a linearly separable, 2D data, the code gives the following decision boundary:

The code here is inspired by the repository try-tf.

tf-svm's People

Contributors

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

tf-svm's Issues

Wrong computation of vector norm

You compute the regularization loss by the following:

regularization_loss = 0.5 * tf.reduce_sum(tf.square(W))

But to compute for the norm of a vector, you must get the square root of the sum of squared elements in the vector, i.e.

tf.sqrt(tf.reduce_sum(W ** 2))

That might throw an error of the data type being int64, so,

tf.sqrt(tf.reduce_sum(W.astype(np.float32) ** 2))

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.