Git Product home page Git Product logo

mlearning's Introduction

Machine learning

Description

Machine learning is quite a fascinating subfield of computer science so I decided to learn more about it. This repository contains some of the code that I have written in order to introduce myself to various concepts of machine learning.

Who knows, maybe one day this will become an open source machine learning library... It may not be the TensorFlow but this code should give you a basic understanding of the fundamentals. I will try to comment the code the best I can and give some basic theory behind the concepts in this README file.

NOTE: Readers should be familiar with linear algebra and calculus.

Multivariable Linear Regression

In statistics, linear regression is an approach for modeling the relationship between a scalar dependent variable y and one or more explanatory variables (or independent variables) denoted x).

In a nutshell this means that for any two given data sets of points X such that x in X and Y such that y in Y we are trying to find a relationship F such that F(x) = y where x represents the input state and y represents the output for the corresponding input state x.

In this case we are investigating F(x) that looks something like this:

Linear function

i.e. we are trying to find a set of coefficients C such that F(x) is as close to y as possible. Note that x_0 = 1 and is called the bias term.

Cost Function

We measure how well F(x) describes y using the cost function:

Cost function

where x^(i) is the i-th set of inputs (or features), y^(i) is the output for x^(i) and m is the number of training examples. We can write this in a vector form as:

Cost in vector form

where C is a vector representing all coefficients, X is the matrix where every row is a vector x^(i) where i is between 1 and m, and y is a vector representing all outputs y^(i).

Gradient Descent

In order to find the coefficients C that minimise our cost function J(C) we use the following algorithm:

Gradient descent 1

where alpha is the learning rate. When we substitute our cost function we get:

Gradient descent 2

The idea behind this is that C_i will converge to some vector V which will be the best set of coefficients for our relation F(x) to predict y. We can choose alpha to be a scalar or a diagonal matrix if we want to adjust the learning rate differently for individual coefficients.

Logistic Regression

Instead of our output vector \vec{y} having components that are in a continuous range of values, they will be 0 or 1.

We use sigmoid function as our hypothesis representation

F_C(\vec{x}) = g(X \cdot C) = \frac {1}{1 - e^{-X \cdot C}}

y = \begin{cases} 1 \text{if } F_C(\vec{x}) \geq 0.5 \ 0 \text{if }  F_C(\vec{x}) \less 0.5 \end{cases}

Cost Function for Logistic Regression

Cost function is:

J(C) = \frac{1}{m}(-\vec{y}^T \cdot \log{(g(X\cdot C))} - (1 - \vec{y})^T \cdot \log{(1 - g(X\cdot C))})

This cost function is chosen because it approaches infinity if g(X\cdot C) = 1 while y = 0 and vice versa. Also, the gradient of this function looks much like the gradient of the cost function for the linear regression.

Gradient Descent

Using the cost function above our algorithm to find the coefficients looks like this:

C_{i + 1} = C_i - \alpha \frac{1}{m} X^T \cdot (g(X \cdot C) - \vec{y})

References

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.