29 lines
573 B
Python
Executable File
29 lines
573 B
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: UTF-8 -*-
|
|
import numpy as np
|
|
from sklearn import datasets, linear_model
|
|
|
|
dataPath = r"./multiple.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])
|
|
yPred = regr.predict(xPred.reshape(1, -1))
|
|
|
|
print yPred
|