1 of 29

The Fundamentals of Machine Learning

Asrul Abdullah

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

2 of 29

Contents

  • What is Machine Learning ?
  • Why Use Machine Learning ?
  • Types of Machine Learning Systems
  • Main Challenges of Machine Learning

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

3 of 29

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

4 of 29

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

5 of 29

Why Use Machine Learning ?

Traditional Approach

Machine Learning Approach

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

6 of 29

Machine Learning is great for :

  • Problems for which existing solutions require a lot of hand-tuning or long lists of rules: one Machine Learning algorithm can often simplify code and perform better.
  • Complex problems for which there is no good solution at all using a traditional approach: the best Machine Learning techniques can find a solution.
  • Fluctuating environments: a Machine Learning system can adapt to new data
  • Getting insights about complex problems and large amounts of data.

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

7 of 29

Type of Machine Learning

  • Whether or not they are trained with human supervision (supervised, unsupervised, semi supervised, and Reinforcement Learning)

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

8 of 29

Supervised / Unsupervised Learning

  • There are four major categories: supervised learning, unsupervised learning, semisupervised learning, and Reinforcement Learning. �

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

9 of 29

Supervised Learning

  • In supervised learning, the training data you feed to the algorithm includes the desired solutions, called labels

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

10 of 29

Supervised Learning

  • A typical supervised learning task is classification. The spam filter is a good example of this: it is trained with many example emails along with their class (spam or ham), and it must learn how to classify new emails
  • Another typical task is to predict a target numeric value, such as the price of a car, given a set of features (mileage, age, brand, etc.) called predictors. This sort of task is called regression

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

11 of 29

Supervised Learning

  • Here are some of the most important supervised learning algorithms�• k-Nearest Neighbors�• Linear Regression�• Logistic Regression�• Support Vector Machines (SVMs)�• Decision Trees and Random Forests�• Neural networks �

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

12 of 29

Unsupervised Learning

  • In unsupervised learning, as you might guess, the training data is unlabeled. The system tries to learn without a teacher ��

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

13 of 29

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

14 of 29

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

15 of 29

Example

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

16 of 29

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

17 of 29

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

18 of 29

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

19 of 29

Main Challenges of Machine Learning

  • Insufficient Quantity of Training Data

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

20 of 29

Main Challenges of Machine Learning

  • Nonrepresentative Training Data

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

21 of 29

Main Challenges of Machine Learning

  • Poor Quality Data

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

  • If some instances are clearly outliers, it may help to simply discard them or try to fix the errors manually.
  • If some instances are missing a few features (e.g., 5% of your customers did not specify their age), you must decide whether you want to ignore this attribute altogether, ignore these instances, fill in the missing values (e.g., with the median age), or train one model with the feature and one model without it, and so on.

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

22 of 29

Main Challenges of Machine Learning

  • Irrelevant Features

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.

  • Feature selection: selecting the most useful features to train on among existing features.
  • Feature extraction: combining existing features to produce a more useful one (as we saw earlier, dimensionality reduction algorithms can help). ��

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

23 of 29

Main Challenges of Machine Learning

  • Overfitting the Training Data. It means that the model performs well on the training data, but it does not generalize well �

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

24 of 29

Main Challenges of Machine Learning

Universitas Muhammadiyah Pontianak

asrulabdullah.my.id

inovasi, kolaborasi & integritas

25 of 29

Main Challenges of Machine Learning

  • underftting is the opposite of overfitting: it occurs when your�model is too simple to learn the underlying structure of the data. �a linear model of life satisfaction is prone to underfit; reality is just more complex than the model, so its predictions are bound to be inaccurate, even on the training examples. �

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

26 of 29

Testing and Validating

  • A better option is to split your data into two sets: the training set and the test set. As these names imply, you train your model using the training set, and you test it using the test set �

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

27 of 29

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

28 of 29

Hyperparameter Tuning and Model Selection

  • A common solution to this problem is called holdout validation: you simply hold out part of the training set to evaluate several candidate models and select the best one. The new heldout set is called the validation set

�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

29 of 29

Main Challenges of Machine Learning

  • Data Mismatch

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