本文介紹了如何解決R和Java中的異常";EVAL失敗,請求狀態:錯誤代碼:127&QOOT;?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用R和Java顯示預測。
我有5小時的數據。我想從四個小時的數據(關于日期的記憶)預測第五個小時的數據。
通過使用4小時的數據,我創建了新的集合,并將第5小時的預測數據插入到新的集合中。但我收到以下錯誤:
The Exception is eval failed, request status: error code: 127
org.rosuda.REngine.Rserve.RserveException: eval failed, request status: error code: 127
at org.rosuda.REngine.Rserve.RConnection.eval(RConnection.java:233)
at scheduler.scheduler.predictions.getPredictionsofData(predictions.java:45)
at pack.GetCollectionMultithreaded.getPredictionAndInsert(GetCollectionMultithreaded.java:386)
at pack.GetCollectionMultithreaded.runCustomerListAndPredictionEvery5Min(GetCollectionMultithreaded.java:155)
at pack.GetCollectionMultithreaded.main(GetCollectionMultithreaded.java:103)
代碼如下:
public class predictions {
public void getPredictionsofData(DB dbObj){
FileInputStream fis = null;
DBCollection network_device_realtime = dbObj.getCollection("mycollectionname");
DBObject return_dobject = null;
// For Network device1 realtime
try{
List<String> listOfIps = network_device_realtime.distinct("hostId");
RConnection c = new RConnection(Rhost,Rport);
c.eval("library(RMongo)");
c.eval("library(plyr)");
c.eval("library(randomForest)");
c.eval(" db <- mongoDbConnect('demo','localhost',27017)");
for( int i= 0 ;i<listOfIps.size(); i++){
float my_predicted_date = 0 ;
BasicDBObject criteria = new BasicDBObject();
BasicDBObject projections = new BasicDBObject();
criteria.put("hostId",listOfIps.get(i));
projections.put("runtimeMillis", 1);
DBCursor cursor = network_device_realtime.find(criteria,projections).sort(new BasicDBObject("runtimeMillis",-1)).limit(1);
while(cursor.hasNext()) {
BasicDBObject obj = (BasicDBObject) cursor.next();
my_predicted_date = (float) obj.getDouble("runtimeMillis");
}
// Set predict date for testing purpose
my_predicted_date = my_predicted_date-(4*60*60*1000);
// for calculating predictions next 24 hrs
for(int j = 1; j <= 12 ;j++){
my_predicted_date = my_predicted_date+(300*1000);//j*60*60*1000calculating next hrs data
System.out.println("Date Gen in network: " +my_predicted_date);
c.eval("query <- dbGetQuery(db,'"+network_device_realtime+"','{"hostId":""+listOfIps.get(i)+"","cpuUtilization":{"$ne":"null"},"memoryUtilization":{"$ne":"NaN"},"runtimeMillis":{"$ne":"null"}}')");
c.eval("date <- query$runtimeMillis");
c.eval("host_id <- query$hostId");
c.eval("cpu <- query$cpuUtilization ");
c.eval("memory <- query$memoryutil");
c.eval("all_data<-data.frame(cpu,date)");
c.eval("training<- all_data");
c.eval("rf_fit<-randomForest(memory~date,data=training)");
c.eval("df <- data.frame(date="+my_predicted_date+ ")");
c.eval("predictions<-predict(rf_fit,newdata=new)");
REXP memory_predictions= c.eval("predictions");
c.eval("rf_fit<-randomForest(cpu~date,data=training)");
c.eval("df <- data.frame(date="+my_predicted_date+ ")");
c.eval("predictions<-predict(rf_fit,newdata=new)");
REXP cpu_predictions= c.eval("predictions");
String json = "";
json ="{"memoryUtilization":"+ memory_predictions + ","cpuUtilization" : "+ cpu_predictions + ","hostId" : ""+ listOfIps.get(i) + "","runtimeMillis":"+my_predicted_date+","deviceType":"snmp"}";
return_dobject=(DBObject) JSON.parse(json);
dbObj.getCollection("prediction").insert(return_dobject);
}
}
c.close();
}
catch(Exception e){
System.out.println("ERROR: In Connection to R ");
System.out.println("The Exception is "+ e.getMessage());
e.printStackTrace();
}
}
}//class
在此代碼中,我在以下行收到錯誤:
c.eval("rf_fit<-randomForest(memory~date,data=training)");
如何解決此錯誤?
推薦答案
此異常主要是由于報表中的數據引起的
c.eval("rf_fit<-randomForest(memory~date,data=training)");
包含空。
這可能是由于數據幀中的錯誤。
請檢查一次。
這篇關于如何解決R和Java中的異常";EVAL失敗,請求狀態:錯誤代碼:127&QOOT;?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,