29 lines
587 B
Python
29 lines
587 B
Python
|
#!/usr/bin/env python
|
||
|
# -*- coding: UTF-8 -*-
|
||
|
import numpy as np
|
||
|
from sklearn import datasets, linear_model
|
||
|
|
||
|
dataPath = r"./multipleDummy.csv"
|
||
|
deliveryData = np.genfromtxt(dataPath, delimiter=',')
|
||
|
|
||
|
print "data"
|
||
|
print deliveryData
|
||
|
|
||
|
X = deliveryData[:, :-1]
|
||
|
Y = deliveryData[:, -1]
|
||
|
|
||
|
print "X:", X
|
||
|
print "Y:", Y
|
||
|
|
||
|
regr = linear_model.LinearRegression()
|
||
|
regr.fit(X, Y)
|
||
|
|
||
|
print "coefficients:", regr.coef_
|
||
|
print "intercept:", regr.intercept_
|
||
|
|
||
|
# 转换成一维数组,否则执行predict函数时报错
|
||
|
xPred = np.array([102, 6, 0, 1, 0])
|
||
|
yPred = regr.predict(xPred.reshape(1, 5))
|
||
|
#
|
||
|
print yPred
|