码迷,mamicode.com
首页 > 其他好文 > 详细

线性回归(Linear Regression)

时间:2017-09-02 19:55:06      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:path   ict   div   python   blog   csv   imp   intercept   线性   

from numpy import genfromtxt
from sklearn import linear_model

datapath=r"Delivery_Dummy.csv"
data = genfromtxt(datapath,delimiter=",")

x = data[1:,:-1]
y = data[1:,-1]
print x
print y

mlr = linear_model.LinearRegression()

mlr.fit(x, y)

print mlr
print "coef:"
print mlr.coef_
print "intercept"
print mlr.intercept_

xPredict =  [90,2,0,0,1]
yPredict = mlr.predict(xPredict)

print "predict:"
print yPredict

 

X
[[ 100.    4.    0.    1.    0.]
 [  50.    3.    1.    0.    0.]
 [ 100.    4.    0.    1.    0.]
 [ 100.    2.    0.    0.    1.]
 [  50.    2.    0.    0.    1.]
 [  80.    2.    0.    1.    0.]
 [  75.    3.    0.    1.    0.]
 [  65.    4.    1.    0.    0.]
 [  90.    3.    1.    0.    0.]
 [  90.    2.    0.    0.    1.]]
Y
[ 9.3  4.8  8.9  6.5  4.2  6.2  7.4  6.   7.6  6.1]

  

 

线性回归(Linear Regression)

标签:path   ict   div   python   blog   csv   imp   intercept   线性   

原文地址:http://www.cnblogs.com/wlc297984368/p/7467438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!