This repository has been archived on 2020-04-25. You can view files and clone it, but cannot push or open issues or pull requests.
ml/regression/MultipleRegDelveryExample.py

29 lines
573 B
Python
Raw Normal View History

2020-02-23 14:14:06 +00:00
#!/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