Skip to main content

Machine Learning Algorithms tutorials (mainly in Python3)

machine-learning

license Python 3.5 Python 3.6
This is a continuously updated repository that documents personal journey on learning data science, machine learning related topics.
Goal: Introduce machine learning contents in Jupyter Notebook format. The content aims to strike a good balance between mathematical notations, educational implementation from scratch using Python's scientific stack including numpy, numba, scipy, pandas, matplotlib, etc. and open-source library usage such as scikit-learn, pyspark, gensim, keras, pytorch, tensorflow, etc.

Documentation Listings

search

Information Retrieval, some examples are demonstrated using ElasticSearch.

time_series

Forecasting methods for timeseries-based data.
  • Getting started with time series analysis with Exponential Smoothing (Holt-Winters). [nbviewer][html]
  • Framing time series problem as supervised-learning. [nbviewer][html]
  • First Foray Into Discrete/Fast Fourier Transformation. [nbviewer][html]

projects

End to end project including data preprocessing, model building.

ab_tests

A/B testing, a.k.a experimental design. Includes: Quick review of necessary statistic concepts. Methods and workflow/thought-process for conducting the test and caveats to look out for.
  • Frequentist A/B testing (includes a quick review of concepts such as p-value, confidence interval). [nbviewer][html]

model_selection

Methods for selecting, improving, evaluating models/algorithms.
  • K-fold cross validation, grid/random search from scratch. [nbviewer][html]
  • AUC (Area under the ROC curve and precision/recall curve) from scratch (includes the process of building a custom scikit-learn transformer). [nbviewer][html]
  • Evaluation metrics for imbalanced dataset. [nbviewer][html]
  • Detecting collinearity amongst features (Variance Inflation Factor for numeric features and Cramer's V statistics for categorical features), also introduces Linear Regression from a Maximum Likelihood perspective and the R-squared evaluation metric. [nbviewer][html]
  • Curated tips and tricks for technical and soft skills. [nbviewer][html]
  • Partial Dependece Plot (PDP), model-agnostic approach for directional feature influence. [nbviewer][html]
  • Kullback-Leibler (KL) Divergence. [nbviewer][html]

big_data

Exploring big data tools, such as Spark and H2O.ai. For those interested there's also a pyspark rdd cheatsheet and pyspark dataframe cheatsheet that may come in handy.
  • Local Hadoop cluster installation on Mac. [markdown]
  • PySpark installation on Mac. [markdown]
  • Examples of manipulating with data (crimes data) and building a RandomForest model with PySpark MLlib. [nbviewer][html]
  • PCA with PySpark MLlib. [nbviewer][html]
  • Tuning Spark Partitions. [nbviewer][html]
  • H2O API walkthrough (using GBM as an example). [nbviewer][html]
  • Spark MLlib Binary Classification (using GBM as an example). [raw zeppelin notebook][Zepl]

dim_reduct

Dimensionality reduction methods.
  • Principal Component Analysis (PCA) from scratch. [nbviewer][html]
  • Introduction to Singular Value Decomposition (SVD), also known as Latent Semantic Analysis/Indexing (LSA/LSI). [nbviewer][html]

recsys

Recommendation system with a focus on matrix factorization methods. Starters into the field should go through the first notebook to understand the basics of matrix factorization methods.
  • Alternating Least Squares with Weighted Regularization (ALS-WR) from scratch. [nbviewer][html]
  • ALS-WR for implicit feedback data from scratch & Mean Average Precision at k (mapk) and Normalized Cumulative Discounted Gain (ndcg) evaluation. [nbviewer][html]
  • Bayesian Personalized Ranking (BPR) from scratch & AUC evaluation. [nbviewer][html]
  • WARP (Weighted Approximate-Rank Pairwise) Loss using lightfm. [nbviewer][html]
  • Factorization Machine from scratch. [nbviewer][html]
  • Content-Based Recommenders:
    • (Text) Content-Based Recommenders. Introducing Approximate Nearest Neighborhood (ANN) - Locality Sensitive Hashing (LSH) for cosine distance from scratch. [nbviewer][html]
  • Approximate Nearest Neighborhood (ANN):
    • Benchmarking ANN implementations (nmslib). [nbviewer][html]
  • Calibrated Recommendation. [nbviewer][html]

trees

Tree-based models for both regression and classification tasks.
  • Decision Tree from scratch. [nbviewer][html]
  • Random Forest from scratch and Extra Trees. [nbviewer][html]
  • Gradient Boosting Machine (GBM) from scratch. [nbviewer][html]
  • Xgboost API walkthrough (includes hyperparmeter tuning via scikit-learn like API). [nbviewer][html]
  • LightGBM API walkthrough and a discussion about categorical features in tree-based models. [nbviewer][html]

association_rule

Also known as market-basket analysis.

clustering

TF-IDF and Topic Modeling are techniques specifically used for text analytics.
  • TF-IDF (text frequency - inverse document frequency) from scratch. [nbviewer][html]
  • K-means, K-means++ from scratch; Elbow method for choosing K. [nbviewer][html]
  • Gaussian Mixture Model from scratch; AIC and BIC for choosing the number of Gaussians. [nbviewer][html]
  • Topic Modeling with gensim's Latent Dirichlet Allocation(LDA). [nbviewer][html]

data_science_is_software

Best practices for doing data science in Python.

deep_learning

Curated notes on deep learning.
  • Softmax Regression from scratch. [nbviewer][html]
  • Softmax Regression - Tensorflow hello world. [nbviewer][html]
  • Multi-layers Neural Network - Tensorflow. [nbviewer][html]
  • Convolutional Neural Network (CNN) - Tensorflow. [nbviewer][html]
  • Recurrent Neural Network (RNN).
  • Word2vec (skipgram + negative sampling) using Gensim (includes text preprocessing with spaCy). [nbviewer][html]

keras

For those interested there's also a keras cheatsheet that may come in handy.
  • Multi-layers Neural Network (keras basics). [nbviewer][html]
  • Multi-layers Neural Network hyperparameter tuning via scikit-learn like API. [nbviewer][html]
  • Convolutional Neural Network (CNN)
    • Image classification basics. [nbviewer][html]
    • Introduction to Residual Networks (ResNets) and Class Activation Maps (CAM). [nbviewer][html]
  • Recurrent Neural Network (RNN) - language modeling basics. [nbviewer][html]

text_classification

Naive Bayes and Logistic Regression for text classification.
  • Building intuition with spam classification using scikit-learn (scikit-learn hello world). [nbviewer][html]
  • Bernoulli and Multinomial Naive Bayes from scratch. [nbviewer][html]
  • Logistic Regression (stochastic gradient descent) from scratch. [nbviewer][html]
  • Chi-square feature selection from scratch. [nbviewer][html]

networkx

Graph library other than networkx are also discussed.
  • PyCon 2016: Practical Network Analysis Made Simple. Quickstart to networkx's API. Includes some basic graph plotting and algorithms. [nbviewer][html]
  • Influence Maximization from scratch. Includes discussion on Independent Cascade (IC), Submodular Optimization algorithms including Greedy and Lazy Greedy, a.k.a Cost Efficient Lazy Forward (CELF) [nbviewer][html]

regularization

Building intuition on Ridge and Lasso regularization using scikit-learn.

ga

Genetic Algorithm. Math-free explanation and code from scratch.
  • Start from a simple optimization problem and extending it to traveling salesman problem (tsp).
  • View [nbviewer][html]

unbalanced

Choosing the optimal cutoff value for logistic regression using cost-sensitive mistakes (meaning when the cost of misclassification might differ between the two classes) when your dataset consists of unbalanced binary classes. e.g. Majority of the data points in the dataset have a positive outcome, while few have negative, or vice versa. The notion can be extended to any other classification algorithm that can predict class’s probability, this documentation just uses logistic regression for illustration purpose.
  • Visualize two by two standard confusion matrix and ROC curve with costs using ggplot2.
  • View [Rmarkdown]

clustering_old

A collection of scattered old clustering documents in R.
  • Toy sample code of the LDA algorithm (gibbs sampling) and the topicmodels library. [Rmarkdown]
  • k-shingle, Minhash and Locality Sensitive Hashing for solving the problem of finding textually similar documents. [Rmarkdown]
  • Introducing tf-idf (term frequency-inverse document frequency), a text mining technique. Also uses it to perform text clustering via hierarchical clustering. [Rmarkdown]
  • Some useful evaluations when working with hierarchical clustering and K-means clustering (K-means++ is used here). Including Calinski-Harabasz index for determine the right K (cluster number) for clustering and boostrap evaluation of the clustering result’s stability. [Rmarkdown]

linear_regression

  • Training Linear Regression with gradient descent in R, briefly covers the interpretation and visualization of linear regression's summary output. [Rmarkdown]

Python Programming

  • Parallel programming with Python (threading, multiprocessing, concurrent.futures, joblib). [nbviewer][html]
  • Understanding iterables, iterator and generators. [nbviewer][html]
  • Cohort analysis. Visualizing user retention by cohort with seaborn's heatmap and illustrating pandas's unstack. [nbviewer][html]
  • Logging module. [nbviewer][html]
  • Data structure, algorithms from scratch. [folder]
  • Cython and Numba quickstart for high performance Python. [nbviewer][html]
  • Optimizing Pandas (e.g. reduce memory usage using category type). [nbviewer][html]
  • Unittest. [Python script]
  • Using built-in data structure and algorithm. [nbviewer][html]
  • Tricks with strings and text. [nbviewer][html]
  • Python's decorators (useful script for logging and timing function). [nbviewer][html]
  • Pandas's pivot table. [nbviewer][html]
  • Quick introduction to classmethod, staticmethod and property. [nbviewer][html]

Comments

Post a Comment

Popular posts from this blog

Introduction to Machine Learning in Python

Python tutorials for introduction to machine learning Introduction to Machine Learning in Python This repository provides instructional material for machine learning in python. The material is used for two classes taught at NYU Tandon by  Sundeep Rangan : EE-UY / CS-UY 4563: Introduction to Machine Learning (Undergraduate) EL-GY 6123: Introduction to Machine Learning (Graduate) Anyone is free to use and copy this material (at their own risk!). But, please cite the material if you use the material in your own class. Pre-requisites All the software can be run on any laptop (Windows, MAC or UNIX).  Instructions  are also provided to run the code in Google Cloud Platform on a virtual machine (VM). Both classes assume no python or ML experience. However, experience with some programming language (preferably object-oriented) is required. To follow all the mathematical details and to complete the homework exercises, the class assumes undergraduate probability, ...

Python Machine Learning Notebooks (Tutorial style)

Python Machine Learning Notebooks (Tutorial style) Dr. Tirthajyoti Sarkar, Sunnyvale, CA ( You can connect with me on LinkedIn here ) Essential codes/demo IPython notebooks for jump-starting machine learning/data science. You can start with this article that I wrote in Heartbeat magazine (on Medium platform): "Some Essential Hacks and Tricks for Machine Learning with Python" Essential tutorial-type notebooks on Pandas and Numpy Jupyter notebooks covering a wide range of functions and operations on the topics of NumPy, Pandans, Seaborn, matplotlib etc. Basics of Numpy array Basics of Pandas DataFrame Basics of Matplotlib and Descriptive Statistics Tutorial-type notebooks covering regression, classification, clustering, dimensionality reduction, and some basic neural network algorithms Regression Simple linear regression with t-statistic generation Multiple ways to do linear regression in Python and their speed comparison ( check the article I wr...

R tutorials for Data Science, NLP and Machine Learning

R Data Science Tutorials This repo contains a curated list of R tutorials and packages for Data Science, NLP and Machine Learning. This also serves as a reference guide for several common data analysis tasks. Curated list of Python tutorials for Data Science, NLP and Machine Learning . Comprehensive topic-wise list of Machine Learning and Deep Learning tutorials, codes, articles and other resources . Learning R Online Courses tryR on Codeschool Introduction to R for Data Science - Microsoft | edX Introduction to R on DataCamp Data Analysis with R Free resources for learning R R for Data Science - Hadley Wickham Advanced R - Hadley Wickham swirl: Learn R, in R Data Analysis and Visualization Using R MANY R PROGRAMMING TUTORIALS A Handbook of Statistical Analyses Using R , Find Other Chapters Cookbook for R Learning R in 7 simple steps More Resources Awesome-R Repository on GitHub R Reference Card: Cheatsheet R bloggers: blog aggregator R Resources...