Abstract: y F X X X, X, X
Abstract: y F X X X, X, X
import numpy as np
In this section, I will choose a
simple example of solving Linear import matplotlib.pyplot as plt
Regression problem in Python. I
will also compare the solution of Next, we declare and represent
the problem when solved by the data on a graph.
equation (5) and the solution is
found using Python's scikit-learn # height (cm)
library . This is a widely used
Machine Learning library in X = np.array([[147, 150, 153, 158, 163,
165, 168, 170, 173, 175, 178, 180,
Python ). In this example, the
183]]).T
input data has only 1 value (1
dimension) for the convenience of # weight (kg)
illustration in the plane. y = np.array([[ 49, 50, 51, 54, 58, 59,
We have a data table about 60, 62, 63, 64, 66, 67, 68]]).T
height and weight of 15 people as
below: # Visualize data
plt.plot(X, y, 'ro')
The question is: is it possible to
predict a person's weight based plt.axis([140, 190, 45, 75])
on their height? ( In reality, of
plt.xlabel('Height (cm)')
course not, as weight depends on
many other factors, such as plt.ylabel('Weight (kg)')
volume ). Since this blog is about
plt.show()
simple Machine Learning
algorithms, I'll assume that we
can predict it.
x0 = np.linspace(145, 185, 2)
y0 = w_0 + w_1*x0
[ 0.55920496]]
4.3. Solution according
to formula
Next, we will calculate the
coefficients w_1 and w_0 based on
the formula(5)(5). Note: the
pseudo-inverse of a matrix A in
Python is computed
using numpy.linalg.pinv(A), pinv
which stands for pseudo inverse.
# Building Xbar
w_0 = w[0][0]
w_1 = w[1][0]
make any mistake in finding the
print( u'Predict weight of person with
height 155 cm: %.2f (kg), real number:
solution above )
52 (kg)' %(y1) )
Jupyter Notebook source code for
print( u'Predict weight of person with this post.
height 160 cm: %.2f (kg), real number:
56 (kg)' %(y2) )
Predict weight of person with height 160 5.1. Problems that can
cm: 55.74 (kg), real number: 56 (kg)
be solved by Linear
We see that the predicted results Regression
are quite close to the actual data.
Function y ≈ f ( x )=wT x is a linear
function of both w và x . In fact,
4.4. Solution using Linear Regression can be applied
to models that only need to be
scikit-learn library linear in w . For example:
2
Next, we will use Python's scikit- y ≈ w1 x 1+ w2 x2 + w3 x 1 + w4 si n ( x 2 ) +w 5 x 1 x2 + w0
learn library to find the solution. is a linear function of w and thus
can also be solved using Linear
from sklearn import datasets, Regression. For each input data
linear_model x=[ x 1 ; x 2 ] , we calculate new data
x=[ x1 , x2 , x 21 , sin ( x 2 ) , x 1 x 2 ]
~
regr.fit(Xbar, y)
8. Method
Method: Applicate Linear regression
algorithm in expecting the
percentage of color element's weight
based on the data set of L, a, b
among Cyan, Magenta, Yellow,
Medium colors which is collected in
So, before performing Linear previously studied research(ІІ).
Regression, the noise ( outliers ) Tool Description: Calculating and
need to be removed. This step is visualization are shown by Python
called pre-processing. programming language instead of
using Excellent in previously studied
research(ІІ).
The second limitation of Linear
Regression is that it cannot
represent complex models . Although
in the above section we saw that this
method can be applied if the
relationship between the outcome
and the input is not necessarily
linear, this relationship is still much
simpler than in real models.
Furthermore, we will ask ourselves:
how to determine the functions
2
( x 1 , sin ( x2 ) , x 1 x 2 ) as above
9. Result
6. Background and
related work 9.1 Cyan and Medium
In this report, readers need to have database
knowledge about:
Bảng a1. Dữ liệu màu pha Cyan và đỏ), kết quả trả về sẽ là một điểm
Medium được dùng là cơ sở dữ liệu thuộc đường cong màu vàng nói trên.
cho đồ án từng nghiên cứu (ІІ)