使用R线性回归的机器学习 [英] Machine Learning using R linear regression

查看:122
本文介绍了使用R线性回归的机器学习的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将R用于机器学习代码.我的项目方案如下所述. 我使用MongoDB进行数据库存储.在mongo db中,我每5分钟在该集合中有一个集合.添加了一个新文档.集合描述如下.

I used R for machine learning code. My project scenario as mentioned below. I used MongoDB for database storage. In mongo db I had one collection in that collection every 5 min. one new document added. The collection description as below.

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

现在我的问题是,使用以上文档,我想预测接下来的5分钟,10分钟或24小时. cpuUsed和内存值.为此,我编写了如下的R代码

Now my problem is that using above documents I want to predict next 5 min or 10 min or 24 hrs. cpuUsed and memory values. For that I write R code as below

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    

使用此输出,我不知道哪个cpuUsed值用于预测值. 如果有人知道,请帮助我. 谢谢.

Using this output I don't know which cpuUsed value used for predicting values. If any one knows please help me. Thank you.

推荐答案

predict的newdata参数需要包含在拟合中使用的变量:

The newdata parameter of predict needs to contain the variables used in the fit:

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.

然后可以使用new cbind预测值.

You can then cbind the predicted values with new.

这篇关于使用R线性回归的机器学习的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆