第19节--多元线性回归(下)

多元线性回归python代码实现:

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

dataPath = r"D:\eclipse\mars\project\DeepLearningBasicsMachineLearning\Datasets\Delivery.txt"
deliveryData = genfromtxt(dataPath,delimiter='\t')

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)

运行结果:

data:
[[ 100.     4.     9.3]
 [  50.     3.     4.8]
 [ 100.     4.     8.9]
 [ 100.     2.     6.5]
 [  50.     2.     4.2]
 [  80.     2.     6.2]
 [  75.     3.     7.4]
 [  65.     4.     6. ]
 [  90.     3.     7.6]
 [  90.     2.     6.1]]
X:
[[ 100.    4.]
 [  50.    3.]
 [ 100.    4.]
 [ 100.    2.]
 [  50.    2.]
 [  80.    2.]
 [  75.    3.]
 [  65.    4.]
 [  90.    3.]
 [  90.    2.]]
Y:
[ 9.3  4.8  8.9  6.5  4.2  6.2  7.4  6.   7.6  6.1]
coefficients:
[ 0.0611346   0.92342537]
intercept:
-0.868701466782
predicted y: 
C:\Program Files\Anaconda3\lib\site-packages\sklearn\utils\validation.py:386: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
  DeprecationWarning)
[ 10.90757981]
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值