7.4多元线性回归实例1--python机器学习

参考彭亮老师的视频教程:转载请注明出处及彭亮老师原创
视频教程: http://pan.baidu.com/s/1kVNe5EJ


1. 例子


    一家快递公司送货:X1: 运输里程 X2: 运输次数   Y:总运输时间

     

Driving 

Assignment

X1=Miles 

Traveled

X2=Number of Deliveries

Y= Travel Time (Hours)

1

100

4

9.3

2

50

3

4.8

3

100

4

8.9

4

100

2

6.5

5

50

2

4.2

6

80

2

6.2

7

75

3

7.4

8

65

4

6.0

9

90

3

7.6

10

90

2

6.1



目的,求出b0, b1,.... bp:

  y_hat=b 0 +b x 1 +b 2 x 2 + ... +b p x



2. Python代码:

from numpy import genfromtxt
import numpy as np
from sklearn import datasets, linear_model

dataPath = r"D:\MaiziEdu\DeepLearningBasics_MachineLearning\Datasets\Delivery.csv"
deliveryData = genfromtxt(dataPath, delimiter=',')

print "data"
print deliveryData

X = deliveryData[:, :-1]
Y = deliveryData[:, -1]

print "X:"
print X
print "Y: "
print Y

regr = linear_model.LinearRegression()

regr.fit(X, Y)

print "coefficients"
print regr.coef_
print "intercept: "
print regr.intercept_

xPred = [102, 6]
yPred = regr.predict(xPred)
print "predicted y: "
print yPred



你可能感兴趣的:(python机器学习)