AI14 - MachineLearning
AI14 - MachineLearning
Basic
Concepts of Ma-
chine Learning
▪ Table of contents
• 14.1 Introduction
• 14.2 Linear regression
• 14.3 k-NN algorithm
• 14.4 Overfitting and un-
derfitting
14.1 Introduction
Go has many
game rules.
Apply machine
learning
Classification
Introduction
Labeling
cat
• Reinforcement learning is given learning data in the form of rewards and punish-
ments. This is the case where only feedback on the behavior of the program is pro-
vided in a dynamic environment, such as driving a vehicle or playing against an oppo-
nent.
14.2 Linear regression
Supervised learning informs problems and correct answers and enables learn-
ing
• Supervised learning predicts a reasonable output value when a new input value
14.1 Supervised learning:
comes in after learning a given input-output pair.
• In other words, supervised learning can be said to learn a mapping function f(x)
Linear regression
from input to output when input (x) and output (y) are given.
Linear regression
Supervised learning informs problems and correct answers and enables learn-
ing
• Suppose we are given points (1, 10), (2, 20), (3, 30), and (4, 40) as input data in
the form of (x, y). The computer does not yet know that the y value for the x
14.1 Supervised learning:
value is data that can be expressed by the equation 𝑦 = 10𝑥. I want to make the
Linear regression
computer answer 50 by learning 4 given data and inputting x = 5 after learning
is finished.
• Supervised learning is when a computer finds the best function that can explain
this input by itself based on input values, and this problem can be called regres-
sion analysis among supervised learning.
Linear regression
• Regression is the problem of finding the straight line or curve that best describes
the data, usually after plotting the data in a multidimensional space.
• In other words, predicting the function 𝑓(𝑥) while looking at the input 𝑥 and the
output 𝑦 at 𝑦=𝑓(𝑥) is called a regression technique.
Linear regression
• Scikit-learn
– Libraries for Machine Learning
?
Linear regression
Let's implement linear regression with the Scikit-Learn library
• Four students were randomly extracted to measure the height and weight, and
the height was 164, 179, 162, and 170 cm, and their weight was 53, 63, 55, and
59 kg, respectively.
Height
weight
Linear regression
Let's implement linear regression with the Scikit-Learn library
Caution: Input value is a person’s height, 164, 179, 162, 170, respectively.
-> The input of linear regression must be used to use a multi-dimensional array.
Target value
Now, for students with a height of 180 or 185, I would like to find out
how the Regrin Linear Return model we created predicts weight.
To do this, prepare the input data.
I am a
I am a
man
woman (1)
(0)
This data includes data used as an input, targets used as a result of learning, and
feature_names that store the names of the input features.
Linear regression
• Extract only one third item corresponding to the body mass index bmi out of 10 features
• The data used as the input of the function must be a two-dimensional array.
We will just extract only bmi data and use it as an input of linear regression.
Linear regression
Diabetes examples: What is the correlation between the body mass index and the
diabetes level?
train_test_split()
X_train X_test
y_train y_test
Final performance
evaluation
linear re-
gression Model Accuracy
learning
regr.fit() regr.predict()
Linear regression
Diabetes examples:
Separate the diabetes example into training and test data
• Only 80%of the total 442 are used for learning (or training)
• Using the remaining 20%for testing
Diabetes examples: Use all the features in the dataset for linear regression
Linear regression
Diabetes examples: Use all the features in the dataset for linear regression
predicted
value
actual value
Linear regression
There are various methods of calculating the error between y_pred and y_test.
One of them is Mean squared error(MSE):
Where, N is the number of elements, is the ith y_test value, and is the
y_pred estimated by the linear regression model, corresponding to .
Linear regression
Samoyed dog
Height
Dachsund dog
Length
• The Samoyed has a high height value compared to its length, and the lower
Dachshund has a low height value compared to its length.
k-NN algorithm
If you classify by looking at 3
Class A of the number of nearest
neighbors, you belong to
class B, but if you classify by
looking at 5, you belong to
class A.
Class B
sepal length
petal length
sepal width
petal width
Setosa : 0
Versicolor : 1
Virginica: 2.
k-NN algorithm
Setosa : 0
Versicolor : 1
Virginica: 2.
k-NN algorithm