我有一个TSV(制表符分隔值)文件,我需要拼写检查拼写错误和组合单词(即'我爱你'和'Iloveyou').
我在我的机器上安装了Aspell,可以使用aspell()函数在R中运行它.
files <- "train2.tsv"
res <- aspell(files)
str(res)
summary(res)
Run Code Online (Sandbox Code Playgroud)
但是,在R中运行它的输出只是拼写错误的单词列表和可能的建议.
> summary(res)
Possibly mis-spelled words:
[1] "amant" "contaneir" "creat" "ddition" "EssaySet" "EssayText" "experiament" "expireiment" "expirement"
[10] "Fipst" "infomation" "Inorder" "measureing" "mintued" "neccisary" "officialy" "renuminering" "rinsen"
[19] "sticlenx" "sucessfully" "tipe" "vineager" "vinigar" "yar"
> str(res)
Classes ‘aspell’ and 'data.frame': 27 obs. of 5 variables:
$ Original : chr "EssaySet" "EssayText" "expirement" "expireiment" ...
$ File : chr "train2.tsv" "train2.tsv" "train2.tsv" "train2.tsv" ...
$ Line : int 1 1 3 3 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将数据帧写入gzip文件但有问题.
这是我的代码示例:
df1 <- data.frame(id = seq(1,10,1), var1 = runif(10), var2 = runif(10))
gz1 <- gzfile("df1.gz","w" )
writeLines(df1)
Run Code Online (Sandbox Code Playgroud)
错误
writeLines(df1):无效的'text'参数
有什么建议?
编辑:我想写的字符向量的示例行是:
0 | var1:1.5 var2:.55 var7:1250
Run Code Online (Sandbox Code Playgroud)
类标签/ y变量通过"|"与x-vars分隔,变量名通过":"与变量之间的空格分隔.
EDIT2:我为问题的措辞/格式道歉,但结果如下:旧方法:
system.time(write(out1, file="out1.txt"))
# user system elapsed
# 9.772 17.205 86.860
Run Code Online (Sandbox Code Playgroud)
新方法:
writeGzFile <- function(){
gz1 = gzfile("df1.gz","w");
write(out1, gz1);
close(gz1)
}
system.time( writeGzFile())
# user system elapsed
# 2.312 0.000 2.478
Run Code Online (Sandbox Code Playgroud)
非常感谢大家帮助我解决这个问题.
我有一个data.frame有几列,我想加入一个新的data.frame中的一列.
df1 <- data.frame(col1 = 1:3, col2 = 4:6, col3 = 7:9)
Run Code Online (Sandbox Code Playgroud)
如何使用1:9的单列创建新的data.frame?
我很好奇R是否有能力将对象放入向量/列表/数组/等.我使用randomforest包来处理更大的数据的子集,并希望将每个版本存储在列表中.它将类似于:
answers <- c()
for(i in 1:10){
x <- round((1/i), 3)
answers <- (rbind(answers, x))
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想做这样的事情:
answers <- c()
for(i in 1:10){
RF <- randomForest(training, training$data1, sampsize=c(100), do.trace=TRUE, importance=TRUE, ntree=50,,forest=TRUE)
answers <- (rbind(answers, RF))
}
Run Code Online (Sandbox Code Playgroud)
这种工作,但这里是单个RF对象的输出:
> RF
Call:
randomForest(x = training, y = training$data1, ntree = 50, sampsize = c(100), importance = TRUE, do.trace = TRUE, forest = TRUE)
Type of random forest: regression
Number of trees: 10
No. of variables tried at each split: 2
Mean of …Run Code Online (Sandbox Code Playgroud) 我希望使用该GBM软件包进行逻辑回归,但它的回答略微超出0-1范围.我已经尝试了0-1预测(bernoulli和adaboost)的建议分布参数,但这实际上比使用更糟糕gaussian.
GBM_NTREES = 150
GBM_SHRINKAGE = 0.1
GBM_DEPTH = 4
GBM_MINOBS = 50
> GBM_model <- gbm.fit(
+ x = trainDescr
+ ,y = trainClass
+ ,distribution = "gaussian"
+ ,n.trees = GBM_NTREES
+ ,shrinkage = GBM_SHRINKAGE
+ ,interaction.depth = GBM_DEPTH
+ ,n.minobsinnode = GBM_MINOBS
+ ,verbose = TRUE)
Iter TrainDeviance ValidDeviance StepSize Improve
1 0.0603 nan 0.1000 0.0019
2 0.0588 nan 0.1000 0.0016
3 0.0575 nan 0.1000 0.0013
4 0.0563 nan …Run Code Online (Sandbox Code Playgroud) 我有一个字符串:
str1 <- "This is a string, that I've written
to ask about a question, or at least tried to."
Run Code Online (Sandbox Code Playgroud)
我怎么会:
1)计算逗号的数量
2)计算'-ion'的出现次数
有什么建议?
我试图使用特定的编码将.tsv(制表符分隔值)文件读入R.据说这是windows-1252.它有一个标题.
有关代码将其放入数据框的任何建议吗?
我使用一些big.___()软件包在R中使用大型数据集.这是~10演出(100mmR x 15C),看起来像这样:
Price Var1 Var2
12.45 1 1
33.67 1 2
25.99 3 3
14.89 2 2
23.99 1 1
... ... ...
Run Code Online (Sandbox Code Playgroud)
我试图根据Var1和Var2预测价格.
我提出的问题是Var1和Var2是分类/因子变量.
Var1和Var2各有3个级别(1,2和3),但数据集中只有6个组合
(1,1; 1,2; 1,3; 2,2; 2,3; 3,3)
Run Code Online (Sandbox Code Playgroud)
要使用因子变量,biglm()它们必须存在于每个biglm使用的数据块中(我的理解是biglm将数据集分解为"x"个块,并在分析每个块后更新回归参数,以便绕过处理数据集比RAM大.)
我试图对数据进行分组,但我的计算机无法处理它或我的代码错误:
bm11 <- big.matrix(150000000, 3)
bm11 <- subset(x, x[,2] == 1 & x[,3] == 1)
Run Code Online (Sandbox Code Playgroud)
上面给了我一堆这些:
Error: cannot allocate vector of size 1.1 Gb
Run Code Online (Sandbox Code Playgroud)
有没有人有解决这个问题的建议?
我在Windows 7机器上使用R 64位w/4演出RAM.
我正在尝试在python中使用scikit learn来做几个不同的分类器问题(RF,GBM等).除了建立模型和进行预测之外,我还希望看到变量的重要性.我知道有办法获得重要性
importances = clf.feature_importances_
print(importances)
Run Code Online (Sandbox Code Playgroud)
但是我如何得到一些更重要的东西,它具有与变量名称相关的重要性(即summary(gbm)在R或varImp(randomForest)R中),特别是如果它是具有多个级别的分类变量?
r ×10
python ×2
aspell ×1
compression ×1
gbm ×1
gzip ×1
list ×1
missing-data ×1
na ×1
nlp ×1
nltk ×1
rbind ×1
scikit-learn ×1
tsv ×1
vector ×1
vowpalwabbit ×1
zip ×1