(2) Supervised learning: understanding of regression and classification.
(3) Definition of linear regression:
(4) Algorithm matrix and array:
Array: 0/1/2 / 3-dimensional array; 3-dimensional array is RGB.
Matrix: 1. Must be a two-dimensional array; 2. Matrix meets the requirements of special operations.
(5) In order to reduce errors, an error function is introduced:
Learning website: https://blog.csdn.net/wangqianqianya/article/details/82960410?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522158731140119725219920099%2522%252C%2522scm%2522%253A%252220140713.130102334.pc% 255Fall.% 2522% 257D & request_id = 158731140119725219920099 & biz_id = 0 & utm_source = distribute.pc_search_result.none-task-blog-2 ~ all ~ first_rank_v2 ~ rank_v25-10
(6) Optimization of statistical learning algorithm: (least square method) 1. Normal equation; 2. Gradient descent.
Dynamic graph of gradient descent optimization:
After 10 cycles, the loss value changes as follows: w and b gradually approach the values of 12, 4.
After 100 cycles, the loss value changes as follows: the closer w and b are to the values 12,4.
Execution code:
import random
import time
import matplotlib.pyplot as plt
#New data
_xs = [0.1 * x for x in range(0, 10)]
_ys = [12 * i + 4 for i in _xs]
print(_xs)
print(_ys)
w = random.random () #weight
print(w)
b = random.random () #bias
print(b)
# y=wx+b
a1 = []
b1 = []
for i in range(10):
for x, y in zip (_xs, _ys): #traverse _xs and _ys
print("x=",x,"y=",y)
o = w * x + b #predicted value
print("o=")
e = (o-y) #error
print("e=",e)
loss = e ** 2 #loss function
dw = 2 * e * x
db = 2 * e * 1
w = w-0.1 * dw #gradient descent w
b = b-0.1 * db #gradient descent b
print('loss={0},w={1},b={2}'.format(loss, w, b))
a1.append(i)
b1.append(loss)
plt.plot(a1, b1)
plt.pause (0.1)
plt.show()
2. Thinking about what linear regression algorithms can be used for? (Everyone try not to write duplicates)
Answer: Linear regression is a continuous variable prediction, which can predict continuous changes in data such as specific house prices and weather temperature. It can be used as a forecasting tool to predict data more scientifically and accurately.