我怎样才能将R中的树值读入.net?我试过这种方法,但它返回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();
当我在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 *
答案 0 :(得分:1)
以下似乎为我提供了您似乎正在寻找的数据框架。我没有使用您提供的代码获取数据框,即使在R中(如果我们讨论相同的树函数,treeElect也不是数据框)。请注意,我使用R.NET的最新开发分支测试了代码示例;您可能必须对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.
}