Machine Learning on.NET F# FTW!. A few words about me Mathias Brandewinder / @brandewinder ...

34
Machine Learning on .NET F# FTW!

Transcript of Machine Learning on.NET F# FTW!. A few words about me Mathias Brandewinder / @brandewinder ...

Page 1: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Machine Learning on .NET

F# FTW!

Page 2: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

A few words about me

»Mathias Brandewinder / @brandewinder

»Background: economics, operations research

».NET developer for 10~ years (C#, F#)

»Bay.Net San Francisco, SFSharp.org

»Yes I have an accent

»www.clear-lines.com/blog

Page 3: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

I am assuming…

»Few familiar with F#

»Mostly unfamiliar with Data Science /

Machine Learning

»Mostly familiar with C#, VB.NET

»Some familiar with Functional Languages

Page 4: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Why this talk

»Machine Learning, Data

Science are red-hot topics

› ... and relevant to

developers

».NET is under-represented

Page 5: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

My goal

»Can’t introduce F#, Machine Learning under 1h

»Give you a sense for what Machine Learning is

› Highlight some differences with “standard”

development

› Mostly live code

»Illustrate why I think F# is a great fit

Page 6: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

What is Machine Learning?

»"A computer program is said to learn from

experience E with respect to some class of

tasks T and performance measure P, if its

performance at tasks in T, as measured by

P, improves with experience E“ [Tom M.

Mitchell]

Page 7: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

In English, please?

»Program performs a Task using Data

»The more Data, the better it gets

»Rooted in statistics, math

»A Computer Science problem as well

› Used in live software, with changing data

Page 8: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

The plan

»Classification »Regression»Unsupervised

»Type Providers

»Existing .NET libraries

»Algebra»Functional fit

Page 9: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Classification & Regression

Page 10: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Goal

»What does “a day of Machine Learning”

look like?

»Illustrate Classification and Regression

Page 11: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Classification, Regression

»Classification = using data to classify items

› Ex: Spam vs. Ham, Character Recognition, …

»Regression = predicting a number

› Ex: predict price of item given attributes, …

»Both belong to Supervised Learning

› You know what question you are trying to answer

› You use data to fit a predictive model

Page 12: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Support Vector Machine

»Classic algorithm»Tries to separate the 2 classes by the widest possible margin

»Using Accord.NET implementation

Page 13: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Demo

Page 14: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Take-aways

»F# is a first-class citizen in .NET

»Decent libraries: Accord.NET, Math.NET, Alea.cuBase,

»Interactive experience with the REPL

»Syntax matters!

»Classification, Regression, Cross-Validation

Page 15: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Unsupervised

Page 16: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Goal

»Illustrate unsupervised learning

»Functional programming and ML are a

great fit

Page 17: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Writing your own

»Usually not advised

»Useful for ML because

› You don’t always have a library

› As you learn your domain, you may need a

custom model

Page 18: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Most ML algorithms are the same»Read data

»Transform into Features

»Learn a Model from the Features

»Evaluate Model quality

Page 19: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Translates well to FP

»Read data

»Transform into Features -> Map

»Learn a Model from the Features ->

Recursion

»Evaluate Model quality -> Fold/Reduce

Page 20: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Focus on transforms, not objects»Need to transform rapidly Features

› Don’t force your domain to fit my algorithm

› Morph around the shape of the data, pass functions

› Algorithms need to be generic

»FP is fantastic for code reuse

Page 21: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

What is Unsupervised Learning?»“Tell me something about my data”

»Example: Clustering

› Find groups of “similar” entities in my dataset

Page 22: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Example: clustering (1)

Page 23: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Example: clustering (2)

“Assign to closest Centroid”[Distance]

Page 24: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Example: clustering (3)

“Update Centroids based on Cluster”[Reduce]

Page 25: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Example: clustering (4)

“Stop when no change”[Recursion]

Page 26: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Demo

Page 27: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Type Providers

Page 28: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

No data, no learning

»Most of ML effort is spent acquiring data

»Most of the World is not in your Type System

»Unpleasant trade-off:

› Dynamic: easy hacking but runtime exceptions

› Static: safer, but straight-jacket

Page 29: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Demo

Page 30: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Conclusion

Page 31: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

F# is a perfect fit for ML on .NET»Functional style fits very well with ML

»REPL/interactive experience is crucial

»Smooth integration with all of .NET

»Type Providers: static types, without the

pain

Page 32: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

My recommendation

»Take a look at Machine Learning, Data

Science

»Do it with a functional language

»… and preferably, do it using F#

»Workshop this Friday!

Page 33: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Getting involved

»Very dynamic community

»FSharp.org, the F# Foundation

»Machine Learning working group, FsLab.org

»Kaggle.com

Page 34: Machine Learning on.NET F# FTW!. A few words about me  Mathias Brandewinder / @brandewinder  Background: economics, operations research .NET developer.

Contacting me

»[email protected]

»@brandewinder