我的桌面上有一个文件夹,里面有大约2500个文件夹,每个文件夹中都有多个压缩文件,我可以通过手动点击它们解压缩它们,有没有办法通过终端自动完成?
我正在使用topicmodels包中的LDA,我已经在大约30.000个文档上运行它,获得了30个主题,并且获得了主题的前10个单词,它们看起来非常好.但是我想看看哪些文件最有可能属于哪个主题,我该怎么办呢?
myCorpus <- Corpus(VectorSource(userbios$bio))
docs <- userbios$twitter_id
myCorpus <- tm_map(myCorpus, tolower)
myCorpus <- tm_map(myCorpus, removePunctuation)
myCorpus <- tm_map(myCorpus, removeNumbers)
removeURL <- function(x) gsub("http[[:alnum:]]*", "", x)
myCorpus <- tm_map(myCorpus, removeURL)
myStopwords <- c("twitter", "tweets", "tweet", "tweeting", "account")
# remove stopwords from corpus
myCorpus <- tm_map(myCorpus, removeWords, stopwords('english'))
myCorpus <- tm_map(myCorpus, removeWords, myStopwords)
# stem words
# require(rJava) # needed for stemming function
# library(Snowball) # also needed for stemming function
# a <- tm_map(myCorpus, stemDocument, language = "english")
myDtm <- DocumentTermMatrix(myCorpus, …Run Code Online (Sandbox Code Playgroud) 我有一个如下所示的数据框:
_________________id ________________text______
1 | 7821 | "some text here"
2 | 7821 | "here as well"
3 | 7821 | "and here"
4 | 567 | "etcetera"
5 | 567 | "more text"
6 | 231 | "other text"
Run Code Online (Sandbox Code Playgroud)
我想按ID对文本进行分组,因此我可以运行一个聚类算法:
________________id___________________text______
1 | 7821 | "some text here here as well and here"
2 | 567 | "etcetera more text"
3 | 231 | "other text"
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?我从数据库表导入,我有很多数据,所以我不能手动完成.
我有一个700.000+行的数据帧(myDF),每行有两列,id和text.该文本有140个字符文本(推文),我想运行一个情绪分析,我从网上得到它们.但是,无论我尝试什么,我都会在4gb内存的macbook上出现内存问题.
我在想,也许我可以遍历行,例如前10行,然后是第10行......等等.(即使批量为100,我也会遇到问题)这会解决问题吗?以这种方式循环的最佳方法是什么?
我在这里发布我的代码:
library(plyr)
library(stringr)
# function score.sentiment
score.sentiment = function(sentences, pos.words, neg.words, .progress='none')
{
# Parameters
# sentences: vector of text to score
# pos.words: vector of words of postive sentiment
# neg.words: vector of words of negative sentiment
# .progress: passed to laply() to control of progress bar
# create simple array of scores with laply
scores = laply(sentences,
function(sentence, pos.words, neg.words)
{
# split sentence into words with str_split (stringr package)
word.list = str_split(sentence, "\\s+")
words = …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的数组:
array(10) {
[0]=>
string(10) "2012-11-03"
[1]=>
string(1) "1"
[2]=>
string(10) "2012-11-04"
[3]=>
string(1) "3"
[4]=>
string(10) "2012-11-05"
[5]=>
string(1) "2"
[6]=>
string(10) "2012-11-06"
[7]=>
string(1) "7"
[8]=>
string(10) "2012-11-07"
[9]=>
string(1) "4"
}
Run Code Online (Sandbox Code Playgroud)
我想从这里得到一个新的多维数组,它有5个元素,每个元素看起来像这样:$ date => $ number.
array(5) {
[0]=> array(2012-11-03 => 1)
[1]=> array(2012-11-04 => 3)
[2]=> array(2012-11-05 => 2)
[3]=> array(2012-11-06 => 7)
[4]=> array(2012-11-07 => 4)
}
Run Code Online (Sandbox Code Playgroud)
我想使用日期作为跟随它们的值的关键.(我最终想在折线图上绘制这些值,其中x轴有日期,y有值)
我可以编写什么样的(foreach?)循环来执行此操作?
我从以下代码行获取此数组:
$data = "$start_date\n$value\n";
file_put_contents($id . '.csv', $data, FILE_APPEND);
$data = file_get_contents($id . '.csv');
$data_array = …Run Code Online (Sandbox Code Playgroud) 我有800万个唯一的user_id到item_id配对,看起来像这样:
user_id item_id
1 item10
1 item11
1 item12
1 item13
2 item11
2 item13
2 item14
2 item15
3 item10
3 item14
3 item18
Run Code Online (Sandbox Code Playgroud)
我想把它变成以下格式:node1,node2,weight,其中所有节点都是user_id,它们之间的权重是它们共享的item_id的数量.因此,例如,1和2连接,因为它们共享2个item_id [item11和item13],1和3共享1 item_id [item_10],2和3共享1以及...等等.
1,2,2
1,3,1
2,3,1
Run Code Online (Sandbox Code Playgroud)
这将是我正在寻找的最终结果.但是,我有800万行(大约25个唯一的user_id,但很多连接)最有效的方法是什么?我用来从大约50.000行检索类似(但不完全相同)的网络的SQL查询需要很长时间,所以我正在寻找替代方案.我可以用R,php,sql或python来做.