线性回归(Linear Regression)——Scikit Learn实例演示

/ Machine Learning / 没有评论 / 512浏览
from numpy import genfromtxt
import numpy as np
from sklearn import datasets, linear_model

dataPath = r"./data.csv"
deliveryData = genfromtxt(dataPath, delimiter=',')

print ("data")
print (deliveryData)

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

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]]
coefficients
[ 0.0611346 0.92342537]
intercept:
-0.868701466782
predicted y:
[ 10.90757981]