Machine learning

at the intersection of statistics and artificial intelligence

algorithms for inferring unknowns from unknowns

ML Model

A Model is a description of possible data one could observe

Generative Models

To get the conditional probability P(Y|X), generative models estimate the prior P(Y) and likelihood P(X|Y) from training data and use Bayes rule to calculate the posterior P(Y |X):

bayes

we have a notion of the underlying distribution of the data and we want to find the hidden parameters of that distribution. Some approaches are:

Discriminative Models

discriminative models directly assume functional form for P(Y|X) and estimate parameters of P(Y|X) directly from training data. They are more suitable when we only want to find the boundary that separates the data into different classes.

Python modules

There are multiple modules for machine learning in python, which you will regularly use alongside moddules like numpy, scipy, and pandas

Supervised learning

given a some data (Xi,Yi)...(Xn, Yn), choose a function f(x) that takes a (new) data point X and gives you a Y. This is an illposed problem. Very difficult to do unless by making certain assumptions

Regression

Suppose that Xi are real valued, and Yi are real valued

Given an X, figure out what Y is associated to that value. Function that returns values for any given X.

Classification

Suppose we have 20 data points in two dimensions (x1, x2) with two classes/labels (y1, y2)

Unsupervised learning

Given some data (x1,...,xn), find patterns in data (whatever that means)

some types of patterns:

Clustering

Given some points in two dimensional real space (R2), find groups of clusters on the data

Linear Classification

Perceptron

We need to figure how to classify a new point.

Perceptron (classifier)

https://en.wikipedia.org/wiki/Perceptron

https://towardsdatascience.com/perceptron-explanation-implementation-and-a-visual-example-3c8e76b4e2d1

https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Perceptron.html

drawing

The equation looks like this : eq

Support Vector Machine (classifier)

The core idea of SVM is to find a maximum marginal line (or hyperplane in multivariate data) that best divides the dataset into classes.

here's a function to plot svc decision function

Cross validation

cross

code adapted from: https://colab.research.google.com/github/jakevdp/PythonDataScienceHandbook/blob/master/notebooks/05.07-Support-Vector-Machines.ipynb#scrollTo=JN-t-aHksW1p

Finally, we can use a grid search cross-validation to explore combinations of parameters. Here we will adjust C (which controls the margin hardness) and gamma (which controls the size of the radial basis function kernel), and determine the best model:

Exercise

Prepare data from the the Spotify API (or other sources) so it can be used on a Linear Classifier such as the SVM