我正在尝试探索使用GBM h2o进行分类问题来替换逻辑回归(GLM).我的数据中的非线性和相互作用使我认为GBM更合适.
我已经运行了基线GBM(见下文),并将AUC与逻辑回归的AUC进行了比较.GBM的表现要好得多.
在经典线性逻辑回归中,人们将能够看到每个预测变量(x)对结果变量(y)的方向和影响.
现在,我想以同样的方式评估估算GBM的变量重要性.
如何获得每个(两个)类的变量重要性?
我知道变量重要性与逻辑回归中的估计系数不同,但它有助于我理解哪个预测因子会影响哪个类.
其他人提出了类似的问题,但提供的答案对H2O对象不起作用.
任何帮助深表感谢.
example.gbm <- h2o.gbm(
x = c("list of predictors"),
y = "binary response variable",
training_frame = data,
max_runtime_secs = 1800,
nfolds=5,
stopping_metric = "AUC")
Run Code Online (Sandbox Code Playgroud) 我有两个相当大的data.table对象要合并。
dt1 在5列上有500.000.000观察值。 dt2 在2列上有300.000个观察值。这两个对象具有相同的key叫id。
我想left_join从信息dt2到dt1。
例如:
dt1 <- data.table(id = c(1, 2, 3, 4),
x1 = c(12, 13, 14, 15),
x2 = c(5, 6, 7, 8),
x3 = c(33, 44, 55, 66),
x4 = c(123, 123, 123, 123))
dt2 <- data.table(id = c(1, 2, 3, 4),
x5 = c(555, 666, 777, 888))
setkey(dt1, id)
setkey(dt2, id)
dt2[dt1, on="id"]
> dt2[dt1, on="id"]
id x5 x1 x2 x3 …Run Code Online (Sandbox Code Playgroud) 我有专利发明人的合作数据.每个发明人都是一个节点,每个边缘代表两个发明者合作的专利.一些专利有> 2个发明人,因此一些专利用多个边缘表示.
我想要了解至少有一位发明家位于博伊西的专利,但并非所有发明家都位于博伊西.其他专利和发明人需要从选择中排除.
例如:
gg <- graph.atlas(711)
V(gg)$name <- 1:7
V(gg)$city <- c("BOISE","NEW YORK","NEW YORK","BOISE","BOISE","LA","LA")
V(gg)$color <- ifelse(V(gg)$city=="BOISE", "orange","yellow")
gg<-delete.edges(gg, E(gg, P=c(1,2,2,3,2,7,7,6,7,3,3,4,3,5,4,5,5,6,6,1)))
gg <- add.edges(gg,c(1,4,4,5,5,1),attr=list(patent=1))
gg <- add.edges(gg,c(7,5,5,4,4,7),attr=list(patent=2))
gg <- add.edges(gg,c(7,3,3,5,5,7),attr=list(patent=3))
gg <- add.edges(gg,c(2,7,7,6,6,2),attr=list(patent=4))
gg <- add.edges(gg,c(6,4),attr=list(patent=5))
plot(gg, edge.label=E(gg)$patent)
Run Code Online (Sandbox Code Playgroud)
生产:
网络示例http://i60.tinypic.com/34teolg.png
在这个网络中,我只想要将所有入射在专利2,3,5边缘的节点子图.
在此示例中,节点1不应该在子图中结束.此外,还应排除从专利#1的节点5到节点4的边缘.
我一直在努力解决这个问题.这可能吗?
我正在寻找有关为相对大的数据集拟合广义线性混合效应模型的策略的建议。
想想我有 10 年内大约 300 支球队的 800 万次美国篮球传球的数据。数据看起来像这样:
data <- data.frame(count = c(1,1,2,1,1,5),
length_pass= c(1,2,5,7,1,3),
year= c(1,1,1,2,2,2),
mean_length_pass_team= c(15,15,9,14,14,8),
team= c('A', 'A', 'B', 'A', 'A', 'B'))
data
count length_pass year mean_length_pass_team team
1 1 1 1 15 A
2 1 2 1 15 A
3 2 5 1 9 B
4 1 7 2 14 A
5 1 1 2 14 A
6 5 3 2 8 B
Run Code Online (Sandbox Code Playgroud)
我想解释一下count球员在传球之前采取的步骤。我有理论动机假设count和之间存在团队级别的差异length_pass,因此多级(即混合效应)模型似乎是合适的。
我的个人级别控制变量是length_pass和 …
I am simulating network change over time using igraph in r and am looking for an efficient and scalable way to code this for use in business.
The main drivers of network change are:
In the first stage, in the network of 100 nodes 10% are randomly connected. The node weights are also assigned at random. The network is undirected. There are 100 stages.
In each of the following stages:
我有一个igraph具有3000个顶点和4000个边的对象.顶点和边都有属性.
其中一个顶点属性是city并且具有所有顶点的有效输入.
我想选择居住在十大最常见城市中的所有顶点,并为这些顶点创建一个新图形.我知道这十大城市是什么.
当我为一个城市这样做时,它工作正常:
new_graph<-induced.subgraph(old_graph, which(V(old_graph$city=="LOS ANGELES")
Run Code Online (Sandbox Code Playgroud)
但是,我确实希望将9个城市纳入其中new_graph.
我可以简单地说明我的which论点吗?或者我应该写一个loop?
有没有人有想法?任何帮助将不胜感激!
我在数据库中有200万个名字.例如:
df <- data.frame(names=c("A ADAM", "S BEAN", "A APPLE A", "A SCHWARZENEGGER"))
> df
names
1 A ADAM
2 S BEAN
3 A APPLE A
4 A SCHWARZENEGGER
Run Code Online (Sandbox Code Playgroud)
' A'如果这些是字符串的最后两个字符,我想删除(空格A).
我知道正则表达式是我们的朋友.如何有效地将正则表达式函数应用于字符串的最后两个字符?
期望的输出:
> output
names
1 A ADAM
2 S BEAN
3 A APPLE
4 A SCHWARZENEGGER
Run Code Online (Sandbox Code Playgroud) 我正在设置一段代码来并行处理我的数据中N组的一些计算foreach.
我有一个涉及调用的计算h2o.gbm.
在我目前的顺序设置中,我使用了大约70%的RAM.
如何在并行代码中正确设置h2o.init()?我担心使用多个内核时可能会耗尽内存.
我的Windows 10机器有12个内核和128GB内存.
这个伪代码会有用吗?
library(foreach)
library(doParallel)
#setup parallel backend to use 12 processors
cl<-makeCluster(12)
registerDoParallel(cl)
#loop
df4 <-foreach(i = as.numeric(seq(1,999)), .combine=rbind) %dopar% {
df4 <- data.frame()
#bunch of computations
h2o.init(nthreads=1, max_mem_size="10G")
gbm <- h2o.gbm(train_some_model)
df4 <- data.frame(someoutput)
}
fwrite(df4, append=TRUE)
stopCluster(cl)
Run Code Online (Sandbox Code Playgroud) 我想计算每个省的房屋数量之间的平均地理距离。
假设我有以下数据。
df1 <- data.frame(province = c(1, 1, 1, 2, 2, 2),
house = c(1, 2, 3, 4, 5, 6),
lat = c(-76.6, -76.5, -76.4, -75.4, -80.9, -85.7),
lon = c(39.2, 39.1, 39.3, 60.8, 53.3, 40.2))
Run Code Online (Sandbox Code Playgroud)
使用geosphere图书馆,我可以找到两所房子之间的距离。例如:
library(geosphere)
distm(c(df1$lon[1], df1$lat[1]), c(df1$lon[2], df1$lat[2]), fun = distHaversine)
#11429.1
Run Code Online (Sandbox Code Playgroud)
如何计算该省所有房屋之间的距离并收集每个省的平均距离?
原始数据集每个省都有数百万个观测值,因此此处的性能也是一个问题。
我有美国城市之间的贸易数据。我有城市(节点)和贸易(边)的属性数据。
考虑下图:
library(igraph)
gg <- graph.atlas(711)
V(gg)$name <- 1:7
V(gg)$city <- c("BOISE","NEW YORK","NEW YORK","BOISE","BOISE","LA","LA")
V(gg)$color <- ifelse(V(gg)$city=="BOISE", "orange","yellow")
gg <- delete.edges(gg, E(gg,P=c(1,2,2,3,2,7,7,6,7,3,3,4,3,5,4,5,5,6,6,1)))
gg <- add.edges(gg,c(1,4,4,5,5,1),attr=list(trade=1))
gg <- add.edges(gg,c(7,5,5,4,4,7),attr=list(trade=2))
gg <- add.edges(gg,c(7,3,3,5,5,7),attr=list(trade=3))
gg <- add.edges(gg,c(2,7,7,6,6,2),attr=list(trade=4))
gg <- add.edges(gg,c(6,4),attr=list(trade=5))
plot(gg, edge.label=E(gg)$trade)
Run Code Online (Sandbox Code Playgroud)
生成以下内容:
由此,我想将包含边缘属性的边缘列表导出到文本文件。
例如:
[CITY 1], [CITY 2], [TRADE]
Run Code Online (Sandbox Code Playgroud)
对我如何做到这一点有任何帮助吗?看起来很容易,但我真的被困住了。
r ×10
igraph ×4
attributes ×3
h2o ×2
memory ×2
performance ×2
bigdata ×1
character ×1
data.table ×1
dataframe ×1
edges ×1
foreach ×1
gbm ×1
geospatial ×1
gsub ×1
lme4 ×1
merge ×1
mixed-models ×1
regex ×1
sapply ×1
simulation ×1
string ×1
subgraph ×1