Learning from Peng Liang《 Introduction to deep learning: machine learning》 curriculum

Difference from simple linear regression

* Simple linear regression: An independent variable(x)
* multiple linear regression : Multiple arguments(x)
Multiple regression model

y=β0+β1x1+β2x2+ … +βpxp+ε
among:β0,β1,β2… βp Are parameters
ε It's the error value.

Multiple regression equation

E(y)=β0+β1x1+β2x2+ … +βpxp

Estimating multiple regression equation

y_hat=b0+b1x1+b2x2+ … +bpxp,( Estimated value), A sample is used to calculateβ0,β1,β2… βp Point estimationb0, b1, b2,…, bp

estimation method

sendsum of squares Minimum


The operation of multiple linear regression is similar to that of simple linear regression, Operations involving linear algebra and matrix algebra

Example



Time = b0+ b1*Miles + b2 * Deliveries

Description of parameter meaning

* b0: Every extra mile on average, Extended transportation timeb1 hour
* b1: Average one more transport, Extended transportation time b2 hour
On the distribution of errors

* errorε It's a random variable, Mean value is0
* ε The variance of is equal for all independent variables
* Allε The value of is independent
* ε Satisfy normal distribution, And passβ0+β1x1+β2x2+ … +βpxp reflecty Expected value
Code application1(Xi All continuous variables)


#coding=utf-8 # @Author: yangenneng # @Time: 2018-01-17 15:42 #
@Abstract: multiple linear regression (Multiple Regression) algorithm from numpy import genfromtxt import
numpyas np from sklearn import linear_model datapath=
r"D:\Python\PyCharm-WorkSpace\MachineLearningDemo\MultipleRegression\data\data.csv"
# Extract data from a text file and convert tonumpy Array format deliveryData = genfromtxt(datapath,delimiter=',')
print "data" # print deliveryData # Read argumentsX1( Miles shipped),X2( Delivery times) x= deliveryData[1:,1
:-1] # Read dependent variable( Delivery time) y = deliveryData[1:,-1] print "x:",x print "y:",y # Call linear regression model
lr = linear_model.LinearRegression()# Assembly data lr.fit(x, y) print lr print(
"coefficients:") print lr.coef_ print("intercept:") print lr.intercept_ # Forecast
xPredict = [102,6] yPredict = lr.predict(xPredict) print("predict:") print
yPredict


Code application2(Xi Include category variables)



Transcode category variables

#coding=utf-8 # @Author: yangenneng # @Time: 2018-01-17 16:11 #
@Abstract: multiple linear regression (Multiple Regression) algorithm With category variable from numpy import genfromtxt
import numpy as np from sklearn import linear_model datapath=
r"D:\Python\PyCharm-WorkSpace\MachineLearningDemo\MultipleRegression\data\data2.csv"
# Extract data from a text file and convert tonumpy Array format deliveryData = genfromtxt(datapath,delimiter=',')
print "data" # print deliveryData # Read argumentsX1...x5 x= deliveryData[1:,1:-1] #
Read dependent variable y = deliveryData[1:,-1] print "x:",x print "y:",y # Call linear regression model lr =
linear_model.LinearRegression()# Assembly data lr.fit(x, y) print lr print(
"coefficients:") print lr.coef_ print("intercept:") print lr.intercept_ # Forecast
xPredict = [90,2,0,0,1] yPredict = lr.predict(xPredict) print("predict:") print
yPredict