The Fundamentals of Machine Learning
Asrul Abdullah
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Contents
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
What is Machine Learning ?
Machine Learning is the science (and art) of programming computers so they can learn from data.
Machine Learning is the field of study that gives computers the ability to learn without being explicitly programmed
-- Arthur Samuel, 1959
A computer program is said to learn from experience E with respect to some task T and some performance measure P, if its performance on T, as measured by P, improves with experience E
-- Tom Mitchell, 1997
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
The Example
If your spam filter is a Machine Learning program that can learn to flag spam given (spam or ham) emails. In this case, the task T is to flag spam for new emails, the experience E is the training data, and the performance measure P need to be defined, for example we can use the ratio of correctly classified emails. The particular performance measure is called accuracy
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Why Use Machine Learning ?
Traditional Approach
Machine Learning Approach
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Machine Learning is great for :
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Type of Machine Learning
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Supervised / Unsupervised Learning
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Supervised Learning
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Supervised Learning
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Supervised Learning
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Unsupervised Learning
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Unsupervised Learning
Here are some of the most important unsupervised learning algorithms
Clustering�- K-Means�- DBSCAN�- Hierarchical Cluster Analysis (HCA)�
Anomaly detection and novelty detection�- One-class SVM�- Isolation Forest
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Unsupervised Learning
Visualization and dimensionality reduction�- Principal Component Analysis (PCA)�- Kernel PCA�- Locally-Linear Embedding (LLE)�- t-distributed Stochastic Neighbor Embedding (t-SNE)
�Association rule learning�- Apriori�- Eclat �
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Example
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Example
So we decide to model life satisfaction as a linear function of GDP per capita. This step is called model selection. We selected a linear model�
This is where the Linear Regression algorithm comes in: you feed it your training examples and it finds the parameters that make the linear model fit best to your data. This is called training the model. In our case the algorithm finds that the optimal parameter values are θ0 = 4.85 and θ1 = 4.91 × 10–5. �
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Example
import matplotlib.pyplot as plt�import numpy as np�import pandas as pd�import sklearn.linear_model�# Load the data�oecd_bli = pd.read_csv("oecd_bli_2015.csv", thousands=',')�gdp_per_capita = pd.read_csv("gdp_per_capita.csv",thousands=',',delimiter='\t',�encoding='latin1', na_values="n/a") �# Prepare the data�country_stats = prepare_country_stats(oecd_bli, gdp_per_capita)�X = np.c_[country_stats["GDP per capita"]]�y = np.c_[country_stats["Life satisfaction"]]
�# Visualize the data�country_stats.plot(kind='scatter', x="GDP per capita", y='Life satisfaction')�plt.show() �
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Example
# Select a linear model�model = sklearn.linear_model.LinearRegression()�# Train the model�model.fit(X, y)�# Make a prediction for Cyprus�X_new = [[22587]] # Cyprus' GDP per capita�print(model.predict(X_new)) # outputs [[ 5.96242338]] �
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Main Challenges of Machine Learning
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Main Challenges of Machine Learning
By using a nonrepresentative training set, we trained a model that is unlikely to make accurate predictions, especially for very poor and very rich countries.
if the sample is too small, you will have sampling noise
even very large samples can be nonrepresentative if the sampling method is flawed. This is called sampling bias �
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Main Challenges of Machine Learning
if your training data is full of errors, outliers, and noise (e.g., due to poor quality measurements
The truth is, most data scientists spend a significant part of their time doing just that
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Main Challenges of Machine Learning
A critical part of the success of a Machine Learning project is coming up with a good set of features to train on. This process, called feature engineering.
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Main Challenges of Machine Learning
Overfitting happens when the model is too complex relative to the amount and noisiness of the training data. The possible solutions are:�• To simplify the model by selecting one with fewer parameters (e.g., a linear model rather than a high-degree polynomial model), by reducing the number of attributes in the training data or by constraining the model�• To gather more training data�• To reduce the noise in the training data (e.g., fix data errors and remove outliers)
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Main Challenges of Machine Learning
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Main Challenges of Machine Learning
The main options to fix this problem are:�• Selecting a more powerful model, with more parameters�• Feeding better features to the learning algorithm (feature engineering)�• Reducing the constraints on the model (e.g., reducing the regularization hyper‐�parameter) �
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Testing and Validating
It is common to use 80% of the data for training and hold out 20% for testing. However, this depends on the size of the dataset: if it contains 10 million instances, then holding out 1% means your test set will contain 100,000 instances: that’s probably more than enough to get a good estimate of the generalization error �
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Hyperparameter Tuning and Model Selection
So you launch this model into production, but unfortunately it does not perform as well as expected and produces 15% errors. What just happened? The problem is that you measured the generalization error multiple times on the test set, and you adapted the model and hyperparameters to produce the best model for�that particular set. This means that the model is unlikely to perform as well on new data. �
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Hyperparameter Tuning and Model Selection
�This solution usually works quite well. However, if the validation set is too small, then model evaluations will be imprecise: you may end up selecting a suboptimal model by mistake. Conversely, if the validation set is too large, then the remaining training set will be much smaller than the full training set. Why is this bad? Well, since the final model will be trained on the full training set, it is not ideal to compare candidate models trained on a much smaller training set �
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas
Main Challenges of Machine Learning
In some cases, it is easy to get a large amount of data for training, but it is not perfectly representative of the data that will be used in production �
Universitas Muhammadiyah Pontianak
asrulabdullah.my.id
inovasi, kolaborasi & integritas