简体   繁体   English

使用R线性回归的机器学习

[英]Machine Learning using R linear regression

I used R for machine learning code. 我将R用于机器学习代码。 My project scenario as mentioned below. 我的项目方案如下所述。 I used MongoDB for database storage. 我使用MongoDB进行数据库存储。 In mongo db I had one collection in that collection every 5 min. 在mongo db中,我每5分钟在该集合中有一个集合。 one new document added. 添加了一个新文档。 The collection description as below. 集合描述如下。

 {
"_id" : ObjectId("521c980624c8600645ad23c8"),
"TimeStamp" : 1377605638752,
"cpuUsed" : -356962527,
"memory" : 2057344858,
"hostId" : "200.2.2.2"
 }

Now my problem is that using above documents I want to predict next 5 min or 10 min or 24 hrs. 现在我的问题是,使用以上文档,我想预测接下来的5分钟,10分钟或24小时。 cpuUsed and memory values. cpuUsed和内存值。 For that I write R code as below 为此,我编写R代码如下

library('RMongo')
mg1 <- mongoDbConnect('dbname')
query <- dbGetQuery(mg1,'test',"{'hostId' : '200.2.2.2'}")
data1 <- query[]
cpu <- query$cpuUtilization
memory <- query$memory
new <- data.frame(data=1377678051) # set timestamp for calculating results
predict(lm(cpu ~   data1$memory + data1$Date ), new, interval="confidence")

But, when I was execute above code it shows me following output 但是,当我执行上面的代码时,它向我显示以下输出

           fit        lwr       upr
    1    427815904  -37534223 893166030
    2   -110791661 -368195697 146612374
    3    137889445 -135982781 411761671
    4   -165891990 -445886859 114102880
    .
    .
    .
    n    

Using this output I don't know which cpuUsed value used for predicting values. 使用此输出,我不知道哪个cpuUsed值用于预测值。 If any one knows please help me. 如果有人知道,请帮助我。 Thank you. 谢谢。

The newdata parameter of predict needs to contain the variables used in the fit: 预测的newdata参数需要包含在拟合中使用的变量:

new <- data.frame(memory = 1377678051, Date=as.Date("2013-08-28))

Only then it is actually used for prediction, otherwise you get the fitted values. 只有这样,它才实际用于预测,否则您将获得拟合值。

You can then cbind the predicted values with new . 然后,您可以将预测值与new cbind

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

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