Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R H20:如何在文本数据上使用渐变增强?_R_Apache Spark_H2o_Sparklyr_Text2vec - Fatal编程技术网

R H20:如何在文本数据上使用渐变增强?

R H20:如何在文本数据上使用渐变增强?,r,apache-spark,h2o,sparklyr,text2vec,R,Apache Spark,H2o,Sparklyr,Text2vec,我试图实现一个非常简单的ML学习问题,在这里我使用文本来预测一些结果。在R中,一些基本示例是: 导入一些虚假但有趣的文本数据 library(caret) library(dplyr) library(text2vec) dataframe <- data_frame(id = c(1,2,3,4), text = c("this is a this", "this is another",

我试图实现一个非常简单的ML学习问题,在这里我使用文本来预测一些结果。在R中,一些基本示例是:

导入一些虚假但有趣的文本数据

library(caret)
library(dplyr)
library(text2vec)

dataframe <- data_frame(id = c(1,2,3,4),
                        text = c("this is a this", "this is 
                        another",'hello','what???'),
                        value = c(200,400,120,300),
                        output = c('win', 'lose','win','lose'))

> dataframe
# A tibble: 4 x 4
     id            text value output
  <dbl>           <chr> <dbl>  <chr>
1     1  this is a this   200    win
2     2 this is another   400   lose
3     3           hello   120    win
4     4         what???   300   lose
最后,训练算法(例如,使用
插入符号
)使用稀疏矩阵预测
输出

mymodel <- train(x=dtm_train, y =dataframe$output, method="xgbTree")

> confusionMatrix(mymodel)
Bootstrapped (25 reps) Confusion Matrix 

(entries are percentual average cell counts across resamples)

          Reference
Prediction lose  win
      lose 17.6 44.1
      win  29.4  8.8

 Accuracy (average) : 0.264
mymodel混淆矩阵(mymodel)
自举(25次重复)混淆矩阵
(条目是重采样的百分比平均细胞计数)
参考文献
预测输赢
损失17.6 44.1
赢29.48.8
准确度(平均):0.264
我的问题是:

我了解了如何使用
spark\u read\u csv
rsparkling
将数据导入
h20
。 然而,对于第2点。三,。上面我完全迷路了

有没有人能给我一些提示,或者告诉我这种方法在
h2o
中是否可行


非常感谢

您可以通过以下两种方法之一解决此问题--1。首先在R中,然后移动到H2O进行建模或2。完全在H2O中使用H2O的word2vec实现

使用R data.frames和text2vec,然后将稀疏矩阵转换为H2O帧,并在H2O中进行建模

 # Use same code as above to get to this point, then:

 # Convert dgCMatrix to H2OFrame, cbind the response col
 train <- as.h2o(dtm_train)
 train$y <- as.h2o(dataframe$output)

 # Train any H2O model (e.g GBM)
 mymodel <- h2o.gbm(y = "y", training_frame = train,
                   distribution = "bernoulli", seed = 1)
#使用与上述相同的代码达到这一点,然后:
#将dgCMatrix转换为H2OFrame,cbind响应列

train什么是
it\u train
变量?我认为你在代码中遗漏了一步(它几乎可以复制,但还没有)。嘿@ErinLeDell,你是对的。等一下sec@ErinLeDell问题更新!仍然缺少it列车
。你添加了
train\u代币
?第三次很有魅力。;-)但是你在哪里找到了关于word2vec的问题?Text2vec!=Word2vec。问题是如何将稀疏矩阵导出到h2o!方法是将矩阵转换为svmlight格式。Noobie所问的任务是H2O唯一等效于在文本上训练模型的任务——我的意思是你可以在H2O中执行相同的任务(使用Word2Vec)。上面的解决方案允许您继续使用text2vec,但它还需要在R内存中执行文本处理计算(而不是分布式H2O w2v),因此我建议将H2O w2v作为解决方法。@erin ledell仍然不同。h2o允许获得单词或句子的向量(平均单词向量)。但这里的例子是关于单词袋模型和大型稀疏矩阵。顺便说一句,我看了一下h2o是如何将稀疏矩阵强制为内部格式的()-这是一场噩梦。我将发送PR.1)这是错误的-默默地并隐式地将第一列视为目标变量2)即使对于小数据也会工作非常(非常)长的时间sets@noobie,例如,用于将矩阵写入svmlight。然后您可以使用
h2o.uploadFile
读取它。
 # Use same code as above to get to this point, then:

 # Convert dgCMatrix to H2OFrame, cbind the response col
 train <- as.h2o(dtm_train)
 train$y <- as.h2o(dataframe$output)

 # Train any H2O model (e.g GBM)
 mymodel <- h2o.gbm(y = "y", training_frame = train,
                   distribution = "bernoulli", seed = 1)