简体   繁体   English

python LinearRegression 进行实时预测

[英]python LinearRegression make real time prediction

i received data from many captors I want to predict electronic failure with linear regression in real time (i want to add new values to my model)我从许多捕获者那里收到数据 我想用线性回归实时预测电子故障(我想向我的模型添加新值)

i have small example :我有一个小例子:

from sklearn.linear_model import LinearRegression
from sklearn.datasets import make_regression
#dataset
#X : Date in millisecond; temperature degree; humidity %
#y : 0= no problem; 1 = electronic failure
X=[[969695100000,15,10],[969788280000,30,50],[975042120000,20,3]]
y=[0,1,0]
model = LinearRegression()
model.fit(X, y)


# Prediction
Xnew, _ = make_regression(n_samples=3, n_features=3, noise=0.1, random_state=1)
ynew = model.predict(Xnew)
for i in range(len(Xnew)):
    print("X=%s, Predicted=%s" % (Xnew[i], ynew[i]))

i have real data X : Date;我有真实数据 X:日期; temperature and humidity and y, 0 => no problem, 1 the sensor has failed I have new data every days, i want to update my model every day.温度和湿度和 y,0 => 没问题,1 传感器出现故障 我每天都有新数据,我想每天更新我的模型。

my goal is with this data to predict a sensor failure by tomorrow.我的目标是利用这些数据预测明天之前的传感器故障。

my question is: how add data to my model ?我的问题是:如何将数据添加到我的模型中?

i found solution for update model in realtime, i use partial_fit, i updated my code like this :我找到了实时更新模型的解决方案,我使用了partial_fit,我像这样更新了我的代码:

import numpy as np
from sklearn import linear_model
from sklearn.datasets import make_regression

n_samples, n_features = 10, 5

X=[[969695100000,15,10],[969788280000,30,50],[975042120000,20,3]]
y=[0,1,0]
model = linear_model.SGDRegressor()
for i in range(0,1000):
    model.partial_fit(X, y)

Xnew, _ = make_regression(n_samples=3, n_features=3, noise=0.1, random_state=1)
ynew = model.predict(X)
for i in range(len(Xnew)):
    print("X=%s, Predicted=%s" % (Xnew[i], ynew[i]))

i have last question, it's possible to predict y value with only date ?我有最后一个问题,可以仅用日期来预测 y 值吗? actualy for predict y tomorow i need to have all X data, it's possible to predict with only : X=[975042120100] without temperature and humidity, only date in millisecond ?实际上,为了预测明天我需要拥有所有 X 数据,可以仅使用以下内容进行预测:X=[975042120100] 没有温度和湿度,只有以毫秒为单位的日期?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM