1 Star 0 Fork 1

高鑫 / Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LinearRegression.py 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
randerson112358 提交于 2018-12-10 20:42 . Create LinearRegression.py
# Import the libraries
from random import randint
from sklearn.linear_model import LinearRegression
# Create a range limit for random numbers in the training set, and a count of the number of rows in the training set
TRAIN_SET_LIMIT = 1000
TRAIN_SET_COUNT = 100
# Create an empty list of the input training set 'X' and create an empty list of the output for each training set 'Y'
TRAIN_INPUT = list()
TRAIN_OUTPUT= list()
#Create and append a randomly generated data set to the input and output
for i in range(TRAIN_SET_COUNT):
a = randint(0, TRAIN_SET_LIMIT)
b = randint(0, TRAIN_SET_LIMIT)
c = randint(0, TRAIN_SET_LIMIT)
#Create a linear function for the output dataset 'Y'
op = (10*a) + (2*b) + (3*c)
TRAIN_INPUT.append([a,b,c])
TRAIN_OUTPUT.append(op)
predictor = LinearRegression(n_jobs=-1) #Create a linear regression object NOTE n_jobs = the number of jobs to use for computation, -1 means use all processors
predictor.fit(X=TRAIN_INPUT, y=TRAIN_OUTPUT) #fit the linear model (approximate a target function)
X_TEST = [[10,20,30]] #Create our testing data set, the ouput should be 10*10 + 2*20 + 3*30 = 230
outcome = predictor.predict(X=X_TEST) # Predict the ouput of the test data using the linear model
coefficients = predictor.coef_ #The estimated coefficients for the linear regression problem.
print('Outcome: {} \n Coefficients: {}'.format(outcome, coefficients))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gaoxin1999/Python.git
git@gitee.com:gaoxin1999/Python.git
gaoxin1999
Python
Python
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891