简体   繁体   English

R.net阅读树

[英]R.net reading tree

how could I read tree values from R into .net? 如何将R中的树值读入.net? I tried this approach but it returns me null 我尝试过这种方法,但返回的却是null

engine.Evaluate("data=read.spss(file='C:/dev/Anomaly/Vorselaar2011D.sav', to.data.frame=TRUE)");
engine.Evaluate("data$timestamp<-as.Date(as.POSIXct(data$timestamp, origin = \"1582-10-14\", tz = \"GMT\"))");
var data =engine.Evaluate("treeElect<-tree(Electricity_kWh~Water_lh+Day_of_Week+TempOut_mean+GasM3h, data=data)");
var dataset = engine.Evaluate("treeElect").AsDataFrame();

when I do it in R console I can see this output 当我在R控制台中执行此操作时,我可以看到此输出

> treeElect
node), split, n, deviance, yval
      * denotes terminal node

 1) root 365 1006000 146.40  
   2) Water_lh < 214 123   84580  85.46  
     4) GasM3h < 64 94   10540  77.95 *
     5) GasM3h > 64 29   51550 109.80  
      10) Day_of_Week < 5 5    9028 186.30 *
      11) Day_of_Week > 5 24    7148  93.86 *
   3) Water_lh > 214 242  232100 177.40  
     6) Water_lh < 582.25 90   44470 154.70  
      12) GasM3h < 87.75 75   20880 149.00 *
      13) GasM3h > 87.75 15    8857 183.30 *
     7) Water_lh > 582.25 152  113800 190.90  
      14) GasM3h < 54.4 72   29300 175.30 *
      15) GasM3h > 54.4 80   51360 204.90  
        30) Day_of_Week < 1.5 22    5340 231.50 *
        31) Day_of_Week > 1.5 58   24540 194.80 *

The following seems to get me the data frame you seem to be seeking. 以下内容似乎为我提供了您正在寻找的数据框。 I do not get a data frame using the code you provide, even in R (treeElect is not a data frame, if we are talking about the same tree function). 即使在R中,也无法使用您提供的代码获得数据框架(如果我们正在谈论相同的树函数,则treeElect不是数据框架)。 Note that I tested the code sample with the latest development branch of R.NET; 请注意,我使用R.NET的最新开发分支测试了代码示例。 you may have to use a differing command for R.NET 1.5.5, commented below. 您可能必须对R.NET 1.5.5使用不同的命令,如下所述。

private static void ReproTreeEnquiry(REngine e)
{
   e.Evaluate("library(tree)");
   var irtr = e.Evaluate("ir.tr <- tree(Species ~., iris)");
   // the following will print a human readable tree to the console output
   e.Evaluate("print(ir.tr)");
   var aList = irtr.AsList(); // May work only with the latest dev code
   // for R.NET 1.5.5 you may need to do instead:
   aList = e.Evaluate("as.list(tree(Species ~., iris))").AsList();
   var theDataFrame = aList[0].AsDataFrame();
   // Further processing of theDataFrame, etc.
}

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

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