Top Banner
m Machine Learning F# and Accord.net
54

M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Jan 03, 2016

Download

Documents

Toby Stephens
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

m

Machine Learning F# and Accord.net

Page 2: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Alena Dzenisenka• Software architect at Luxoft Poland

• Member of F# Software Foundation Board of Trustees

• Researcher in the field of mathematical theoretical possible in modern programming concepts

• Speaker and active software engineering community member

@lenadroid

Page 3: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Machine Learning

Page 4: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

• Why machine learning?

• What is the data?

• How?

Questions

Page 5: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Data Questions.

Page 6: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Data reality :\

Page 7: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Path to grasping machine learning and data science…

Page 8: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Contents• Multiple Linear

Regression• Logistic Regression

Classification• Neural Networks

Classification• K Means

Clustering• What’s next?

Page 9: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.
Page 10: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

F# for machine learningand data science!

Page 11: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Linear Regression

Page 12: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

MATH

Page 13: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

How to predict?1. Make a guess.2. Measure how wrong the guess

is.3. Fix the error.

Page 14: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Make a guess!

Page 15: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Make a guess?What does it mean?...

Hypothesis /guess :

weights

Page 16: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Find out our mistake…

Cost function/ Mistake function:

… and minimize it:

Page 17: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Mistake function looks like…

Global minimums

Page 18: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

How to reduce the mistake?Update each slope parameter

until Mistake Functionminimum is reached:

Simultaneously

Alpha Learning rate

Derivative Direction of moving

Page 19: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Fix the error

Page 20: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Multiple Linear RegressionX [ ] – Predictors:Statistical data about bike rentals for previous years or months.

Y – Output:Amount of bike rentals we should expect today or some other day in the future.

* Y is not nominal, here it’s numerical continuous range.

Page 21: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Make a guess!

Page 22: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Fix the error

Page 23: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Multiple linear regression: Bike rentals demand

“Talk is cheap. Show me the code.”

Page 24: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

What to remember?1. Simplest regression algorithm

2. Very fast, runs in constant time

3. Good at numerical data with lots of features

4. Output from numerical continuous range

5. Linear hypothesis

6. Uses gradient descent

Linear Regression

Page 25: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Logistic Regression

Page 26: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Hypothesis function

Estimated probability that Y = 1 on input X

Page 27: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Mistake function

Mistake function is the cost for a single training data example

h(x)

Page 28: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Full mistake function

1. Uses the principle of maximum likelihood estimation.

2. We minimize it same way as with Linear Regression

Page 29: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

“Talk is cheap. Show me the code.”

Logistic Regression Classification Example

Page 30: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

What to remember?

• Classification algorithm

• Output is the binary value, either 1 or 0

• Relatively small number of predictors

• Uses logistics function for hypothesis

• Has the cost function that is convex

• Uses gradient descent for correcting the mistake

Logistic Regression

Page 31: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

At this point…

Page 32: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Machine Learning

What society thinks I do…

What other programmers think I do…

Page 33: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

What I really do is…

Page 34: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Neural Networks

Page 35: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Neuron

Page 36: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Neural Networks

Page 37: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Layer transitions!Input

Weights

Activation function

Activation unit(value which is computed and outputted by the node)

Elena Droid
Page 38: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Activation function?

Step activation functionUsed in binary classification

Sigmoid activation functionUses logistic function to perform the activation

Page 39: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Forward propagation

x

x

x

x

a

a

a

a

a

a

a

X = X X =

a1X =

a2

Hypothetic Outputs!

Activation Computational Nodes!

Predictors

Page 40: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Multi class?

ORxxx

aaaaa

xxx

aaaaa

Page 41: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Cost function?

xxxLooks difficult? No, it’s really not so complicated…1. Outputs the vector with size == number of

output classes2. Similar to Logistic Regression cost function3. Finds the mistake of our hypothesis and

real outputs

Page 42: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Minimize the error!

x

x

x

x

Error value

And then… recalculate weights!

Page 43: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

“Talk is cheap. Show me the code.”

Neural Networks Classification Example.

Page 44: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

What to remember?

• Extremely powerful• Slow learning / Fast prediction• Big number of predictors• Complex hierarchical relationships• No need to understand the data• Wide applications

Neural Networks

Page 45: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

K-Means

Page 46: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Clustering

Page 47: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Birth-death percentage rates

Page 48: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

… with clustering K=2

Page 49: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

… with clustering K=3

Page 50: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

… with clustering K=4

Page 51: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

What’s next?

Page 52: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.
Page 53: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

I’m Lena@lenadroid

Page 54: M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.

Thank you!