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＋β１x1+β2x2+ … +βpxp+ε
among ：β0,β１,β2… βp Is a parameter
ε Is the error value

Multiple regression equation

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

Estimating multiple regression equation

y_hat=b0＋b１x1+b2x2+ … +bpxp,（ Estimate ）, A sample is used to calculate β0,β１,β2… βp Point estimation of b0, b1, b2,…, bp

estimation method

send sum 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 time b1 hour
* b1: Average one more transport , Extended transportation time b2 hour
On the distribution of errors

* error ε It's a random variable , The mean value is 0
* ε The variance of is equal for all independent variables
* All ε The value of is independent
* ε Satisfy normal distribution , And through β0＋β１x1+β2x2+ … +βpxp reflect y Expected value of
Code application 1（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 to numpy Array format deliveryData = genfromtxt(datapath,delimiter=',')
print "data" # print deliveryData # Read arguments X1( Miles shipped ),X2( Number of deliveries ) 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 application 2（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 to numpy Array format deliveryData = genfromtxt(datapath,delimiter=',')
print "data" # print deliveryData # Read arguments X1...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