SlideShare a Scribd company logo
1 of 14
Download to read offline
Machine Learning in Rust, Logistic and
Linear Regression From Scratch
Vlad Orlov


volodymyr.orlov@gmail.com
Agenda
How can I build my own


Regressor?


Classifier?


Overview of Rust creates: nalgebra, ndarray, argmin ,
smartcore
Disclamers
In this presentation we won’t talk about:


Why Rust is great for scientific computing and ML


Deep Learning


Large scale ML


GPU, FPGA and other accelerators
ML Refresher: Statistical Learning
When we have


Quantitative response Y


M different predictors: X1, X2, . . . , Xm


Relationship between Y and X


can be written as: Y = f(X) + ϵ
ML Refresher: X and Y
* https://archive.ics.uci.edu/ml/machine-learning-databases/housing/
ML Refresher: Problem Categories
Do we have Y?


Yes! We can do supervised learning


No, unsupervised learning


Y is quantitative or qualitative?


quantitative, we can build a regressor*


qualitative, we can build a classifier
* Classifier is also possible if there is a way to covert numerical response to a category
ML Refresher: Prerequisites
Linear algebra Basic statistics
Probability theory Optimization
ML Refresher: Linear Models


y1
y2
. . .
yn
=
β0 + β1x11 + β2x12
β0 + β1x21 + β2x22
. . .
β0 + β1xn1 + β2xn2
+
ϵ1
ϵ2
. . .
ϵn
Y = Xβ + ϵ
When we have 2 predictors, x1 and x2:
In vector form:
Linear Algebra: nalgebra/ndarray
1 https://nalgebra.org/


2 https://github.com/rust-ndarray
Slicing, decomposition, solver for system of
linear equations


Only 1D vectors and 2D matrices


Can do decomposition and solve equations
in pure Rust
Slicing, decomposition, solver for system of
linear equations, stats functions


Supports arbitrary number of dimensions


You will need BLAS/LAPACK backend to solve
linear equations and matrix decomposition
nalgebra1


ndarray2
All Together: Smartcore*
* http://smartcorelib.org/
22 algorithms


Supervised & unsupervised learning


Matrix decomposition + solvers


Model selection & evaluation


Simple API & user manual with lots of examples


Model serialization/deserialization


Supports Rust vectors, ndarray, nalgebra, etc.
Smartcore, our Mission
Our target: production facing applications + embedded devices + WebAssembly.


Straightforward API with superior documentation is our commitment


Cutting-edge implementations


Minimum dependencies


Great selection of algorithms


Model selection and evaluation toolset


Join our community!
Logistic Regression
* https://en.wikipedia.org/wiki/Sigmoid_function
Y = σ(Xβ)
σ(x) =
1
1 + e−x
Sigmoid function
Optimization: argmin{}*
* http://argmin-rs.org/
Pure rust implementation of convex and nonconvex
optimization methods


Gradient-fee and gradient methods


Supports native vectors and ndarray


Logging and checkpoints
Q&A
My email: volodymyr.orlov@gmail.com


Check out my blog: https://vlad-orlov.com/blog/


This presentation: https://github.com/VolodymyrOrlov/rust4ml

More Related Content

Similar to Machine learning in Rust, implementing logistic and linear regression from scratch

Machine Learning ICS 273A
Machine Learning ICS 273AMachine Learning ICS 273A
Machine Learning ICS 273A
butest
 
Mahout scala and spark bindings
Mahout scala and spark bindingsMahout scala and spark bindings
Mahout scala and spark bindings
Dmitriy Lyubimov
 

Similar to Machine learning in Rust, implementing logistic and linear regression from scratch (20)

Yarn spark next_gen_hadoop_8_jan_2014
Yarn spark next_gen_hadoop_8_jan_2014Yarn spark next_gen_hadoop_8_jan_2014
Yarn spark next_gen_hadoop_8_jan_2014
 
MLSEV. Logistic Regression, Deepnets, and Time Series
MLSEV. Logistic Regression, Deepnets, and Time Series MLSEV. Logistic Regression, Deepnets, and Time Series
MLSEV. Logistic Regression, Deepnets, and Time Series
 
supervised.pptx
supervised.pptxsupervised.pptx
supervised.pptx
 
Joker'14 Java as a fundamental working tool of the Data Scientist
Joker'14 Java as a fundamental working tool of the Data ScientistJoker'14 Java as a fundamental working tool of the Data Scientist
Joker'14 Java as a fundamental working tool of the Data Scientist
 
Azure 機器學習 - 使用Python, R, Spark, CNTK 深度學習
Azure 機器學習 - 使用Python, R, Spark, CNTK 深度學習 Azure 機器學習 - 使用Python, R, Spark, CNTK 深度學習
Azure 機器學習 - 使用Python, R, Spark, CNTK 深度學習
 
Ted Willke, Senior Principal Engineer & GM, Datacenter Group, Intel at MLconf SF
Ted Willke, Senior Principal Engineer & GM, Datacenter Group, Intel at MLconf SFTed Willke, Senior Principal Engineer & GM, Datacenter Group, Intel at MLconf SF
Ted Willke, Senior Principal Engineer & GM, Datacenter Group, Intel at MLconf SF
 
Jay Yagnik at AI Frontiers : A History Lesson on AI
Jay Yagnik at AI Frontiers : A History Lesson on AIJay Yagnik at AI Frontiers : A History Lesson on AI
Jay Yagnik at AI Frontiers : A History Lesson on AI
 
Knowledge graphs, meet Deep Learning
Knowledge graphs, meet Deep LearningKnowledge graphs, meet Deep Learning
Knowledge graphs, meet Deep Learning
 
MachinaFiesta: A Vision into Machine Learning 🚀
MachinaFiesta: A Vision into Machine Learning 🚀MachinaFiesta: A Vision into Machine Learning 🚀
MachinaFiesta: A Vision into Machine Learning 🚀
 
Build, Train, and Deploy ML Models at Scale
Build, Train, and Deploy ML Models at ScaleBuild, Train, and Deploy ML Models at Scale
Build, Train, and Deploy ML Models at Scale
 
MLconf seattle 2015 presentation
MLconf seattle 2015 presentationMLconf seattle 2015 presentation
MLconf seattle 2015 presentation
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
 
Machine Learning ICS 273A
Machine Learning ICS 273AMachine Learning ICS 273A
Machine Learning ICS 273A
 
Python for data science
Python for data sciencePython for data science
Python for data science
 
Introduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowIntroduction to Deep Learning and Tensorflow
Introduction to Deep Learning and Tensorflow
 
Data science and OSS
Data science and OSSData science and OSS
Data science and OSS
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for Python
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Data analysis in R
Data analysis in RData analysis in R
Data analysis in R
 
Mahout scala and spark bindings
Mahout scala and spark bindingsMahout scala and spark bindings
Mahout scala and spark bindings
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Recently uploaded (20)

The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 

Machine learning in Rust, implementing logistic and linear regression from scratch

  • 1. Machine Learning in Rust, Logistic and Linear Regression From Scratch Vlad Orlov volodymyr.orlov@gmail.com
  • 2. Agenda How can I build my own Regressor? Classifier? Overview of Rust creates: nalgebra, ndarray, argmin , smartcore
  • 3. Disclamers In this presentation we won’t talk about: Why Rust is great for scientific computing and ML Deep Learning Large scale ML GPU, FPGA and other accelerators
  • 4. ML Refresher: Statistical Learning When we have Quantitative response Y M different predictors: X1, X2, . . . , Xm Relationship between Y and X 
 can be written as: Y = f(X) + ϵ
  • 5. ML Refresher: X and Y * https://archive.ics.uci.edu/ml/machine-learning-databases/housing/
  • 6. ML Refresher: Problem Categories Do we have Y? Yes! We can do supervised learning No, unsupervised learning Y is quantitative or qualitative? quantitative, we can build a regressor* qualitative, we can build a classifier * Classifier is also possible if there is a way to covert numerical response to a category
  • 7. ML Refresher: Prerequisites Linear algebra Basic statistics Probability theory Optimization
  • 8. ML Refresher: Linear Models y1 y2 . . . yn = β0 + β1x11 + β2x12 β0 + β1x21 + β2x22 . . . β0 + β1xn1 + β2xn2 + ϵ1 ϵ2 . . . ϵn Y = Xβ + ϵ When we have 2 predictors, x1 and x2: In vector form:
  • 9. Linear Algebra: nalgebra/ndarray 1 https://nalgebra.org/ 2 https://github.com/rust-ndarray Slicing, decomposition, solver for system of linear equations Only 1D vectors and 2D matrices Can do decomposition and solve equations in pure Rust Slicing, decomposition, solver for system of linear equations, stats functions Supports arbitrary number of dimensions You will need BLAS/LAPACK backend to solve linear equations and matrix decomposition nalgebra1 ndarray2
  • 10. All Together: Smartcore* * http://smartcorelib.org/ 22 algorithms Supervised & unsupervised learning Matrix decomposition + solvers Model selection & evaluation Simple API & user manual with lots of examples Model serialization/deserialization Supports Rust vectors, ndarray, nalgebra, etc.
  • 11. Smartcore, our Mission Our target: production facing applications + embedded devices + WebAssembly. Straightforward API with superior documentation is our commitment Cutting-edge implementations Minimum dependencies Great selection of algorithms Model selection and evaluation toolset Join our community!
  • 12. Logistic Regression * https://en.wikipedia.org/wiki/Sigmoid_function Y = σ(Xβ) σ(x) = 1 1 + e−x Sigmoid function
  • 13. Optimization: argmin{}* * http://argmin-rs.org/ Pure rust implementation of convex and nonconvex optimization methods Gradient-fee and gradient methods Supports native vectors and ndarray Logging and checkpoints
  • 14. Q&A My email: volodymyr.orlov@gmail.com Check out my blog: https://vlad-orlov.com/blog/ This presentation: https://github.com/VolodymyrOrlov/rust4ml