首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R中的MAXENT分类模型

R中的MAXENT分类模型
EN

Stack Overflow用户
提问于 2014-05-08 05:01:23
回答 1查看 796关注 0票数 0

我试图用R.使用RTextTools包对文本进行分类。

我使用- SVM完成了这一工作(下面的代码运行良好:)

代码语言:javascript
复制
matrix[[i]] <- create_matrix(trainingdata[[i]][,1], language="english",removeNumbers=FALSE, stemWords=FALSE,weighting=weightTf,minWordLength=3)
container[[i]] <- create_container(matrix[[i]],trainingdata[[i]][,2],trainSize=1:length(trainingdata[[i]][,1]),virgin=FALSE)
models[[i]] <- train_models(container[[i]], algorithms=c("SVM"))

但是当我用MAXENT算法做同样的事情时

代码语言:javascript
复制
models[[i]] <- train_models(container[[i]], algorithms=c("MAXENT"))

它给我带来了错误:

代码语言:javascript
复制
Error in Module(module, mustStart = TRUE) : 
  function 'setCurrentScope' not provided by package 'Rcpp'  

当我做回溯时-得到了下面的细节

代码语言:javascript
复制
Module(module, mustStart = TRUE) 
.getModulePointer(x) 
maximumentropy$add_samples 
maximumentropy$add_samples 
train_maxent(feature_matrix, code_vector, l1_regularizer, l2_regularizer,  
maxent(container@training_matrix, as.vector(container@training_codes),  
train_model(container, algorithm, ...) 
train_models(container[[i]], algorithms = c("MAXENT")) 

更新:

代码语言:javascript
复制
sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_Singapore.1252  LC_CTYPE=English_Singapore.1252    LC_MONETARY=English_Singapore.1252
[4] LC_NUMERIC=C                       LC_TIME=English_Singapore.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tm_0.5-10        hash_3.0.1       RTextTools_1.4.2 SparseM_1.03    

loaded via a namespace (and not attached):
 [1] bitops_1.0-6       caTools_1.16       class_7.3-9        e1071_1.6-1        glmnet_1.9-5       grid_3.0.2        
 [7] ipred_0.9-3        KernSmooth_2.23-10 lattice_0.20-23    lava_1.2.4         MASS_7.3-29        Matrix_1.1-2      
[13] maxent_1.3.3.1     nnet_7.3-7         parallel_3.0.2     prodlim_1.4.2      randomForest_4.6-7 Rcpp_0.10.6       
[19] rpart_4.1-5        slam_0.1-31        splines_3.0.2      survival_2.37-7    tau_0.0-16         tools_3.0.2       
[25] tree_1.0-34

有没有办法解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-08 09:28:36

不是一个真正的答案,但由于sessionInfo()的长度过长,所以在这里张贴

代码语言:javascript
复制
library(RTextTools)
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)


attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] RTextTools_1.4.1   tau_0.0-15         glmnet_1.9-5       Matrix_1.0-14      lattice_0.20-23    maxent_1.3.3      
 [7] Rcpp_0.10.5        caTools_1.14       ipred_0.9-2        e1071_1.6-1        class_7.3-9        tm_0.5-9.1        
[13] nnet_7.3-7         tree_1.0-34        randomForest_4.6-7 SparseM_1.03      

loaded via a namespace (and not attached):
 [1] bitops_1.0-6       grid_3.0.2         KernSmooth_2.23-10 MASS_7.3-29        parallel_3.0.2     prodlim_1.3.7     
 [7] rpart_4.1-3        slam_0.1-30        splines_3.0.2      survival_2.37-4    tools_3.0.2 

在我的例子中,所有必需的模块都是在other attached packages下加载的,而在您的例子中,它们是在loaded via a namespace (and not attached)下加载的。

在情况2下,R可以访问包,但用户不能访问。有关更多解释,请参见In R, what does "loaded via a namespace (and not attached)" mean?

我不知道为什么包没有附加在您的情况下,但作为一种解决办法,您可以尝试如下:

代码语言:javascript
复制
#grab list of package names required for RTextTools
# not_attached_list<-dput(names(sessionInfo()$otherPkgs))
#c("RTextTools", "tau", "glmnet", "Matrix", "lattice", "maxent", 
#"Rcpp", "caTools", "ipred", "e1071", "class", "tm", "nnet", "tree", 
#"randomForest", "SparseM")

not_attached_list<-c("RTextTools", "tau", "glmnet", "Matrix", "lattice", "maxent", 
"Rcpp", "caTools", "ipred", "e1071", "class", "tm", "nnet", "tree", 
"randomForest", "SparseM")

#Load the packages manually
sapply(not_loaded_list, require, character.only=TRUE)

#Check in sessionInfo if they have been attached now under 'other attached packages'
sessionInfo()

让我们知道这是否有效..。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23533077

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档