Code Monkey home page Code Monkey logo

scala-ml's Introduction

Machine learning in Scala

NN (Neural network Handwriting Recognition)

Coursera Machine Learning Neural Network Back Propagation implementation in Scala with Scala NLP Breeze. Optimal value search fmincg is implemented with Breeze.optimize in Optimizer.scala.

NN

Some MATLAB conventions may remain as it is used at Coursera, such as index is from 1, NOT 0. For the labels to classify digit, digit 1 is mapped to index 1, digit 0 is mapped to index 10. In Scala implementation, digit 1 is mapped to index 0, and digit 0 is mapped to index 9.

Mechanism

Represent how well/poor the network(theta1, theta2) performs with a cost function, which tells how far away the output of the network is from the correct digit. Feed back the cost to adjust (theta1, theta2) to bring down the cost by running gradient descent. To be able to reach the optima by the descent, the cost function is a convex function.

Cost Function

Estimate the effectiveness of the theta, calculate the penalty/error, or cost.

Cost Function

Back Propagation from output layer towards hidden layer

To feed the cost back and adjust the theta2 to bring the cost down, calculate the gradient of theta2. The optimization function from Breeze utilizes the gradient to run the gradient descent.

Backpopagation Theta2

Back Propagation from hidden layer to Theta1

To feed the cost back and adjust the theta1 to bring the cost down, calculate the gradient of theta1. The optimization function from Breeze utilizes the gradient to run the gradient descent.

Backpropagation Theta2

Derivative Calculus

Derivative

Training / Optimization

The original data contains 5000 digit images. Used 4900 data and 100 iterations of gradients for training the network, and used the remaining 100 for validations. Use the Breeze.optimize package DiffFuction to run the gradient descent(?).

Prediction

Fed the validation data Z.CSV to test as in the Prediction results at YouTube.

Result

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.