twitter數據分析_Twitter上最受歡迎的數據科學文章主題

twitter數據分析

If you’ve written data science articles or are trying to get started, finding the most popular topics is a big help in getting your articles read. Below are the steps to easily determine what these topics are using R and the results of the analysis. This article can also serve as an intro to using an API, and doing some basic text processing in R. Feel free to alter this code to do other Twitter analyses and skip to the end if you’re only interested in the results.

如果您寫過數據科學文章或正在嘗試入門,那么找到最受歡迎的主題對閱讀文章有很大幫助。 以下是輕松確定使用R這些主題和分析結果的步驟。 本文還可以作為使用API??的介紹,以及在R中進行一些基本的文本處理。如果您僅對結果感興趣,請隨意更改此代碼以進行其他Twitter分析,并跳到最后。

Twitter API (The Twitter API)

If you don’t have a twitter account, you need to make one. After that head over to Twitter Developer. After signing in with your new account, you can select the Apps Menu, then Create an App. From there fill out the information about the App’s details, for the most part, this can be left blank except for the App’s name and details.

如果您沒有Twitter帳戶,則需要注冊一個。 之后,前往Twitter開發人員 。 使用新帳戶登錄后,您可以選擇“應用程序菜單”,然后選擇“創建應用程序”。 從那里填寫有關應用程序詳細信息的信息,在大多數情況下,除了應用程序名稱和詳細信息外,可以將其留空。

安裝R軟件包 (Installing R Packages)

We will need 3 R packages to do this project — rtweet, tidyverse, and tidytext. Install these with

我們需要3個R軟件包來完成此項目-rtweet,tidyverse和tidytext。 用這些安裝

install.packages("package-name")

Make sure you load each of these packages in your script with the library() function.

確保使用library()函數在腳本中加載每個軟件包。

收集推文 (Collecting Tweets)

To get tweets we first need to generate a token. We can do that with the create_token() function from the rtweet package. The arguments can be filled in by looking over the information on the page of your new app on the Twitter Developer site. All of these variables are important for security, so whenever you use an API, make sure to take precaution by keeping these tokens and keys private.

要獲取推文,我們首先需要生成一個令牌。 我們可以使用rtweet包中的create_token()函數來實現。 可以通過在Twitter Developer網站上查看新應用程序頁面上的信息來填充參數。 所有這些變量對于安全性都很重要,因此,每當您使用API??時,請確保將這些令牌和密鑰設為私有,以防患于未然。

token <- create_token(app = "<app-name>",
consumer_key = "<consumer-key>",
consumer_secret = "<consumer-secret>",
access_token = "<access-token>",
access_secret = "<access-secret>")

Now to grab tweets! Use the get_timeline() function to get access to the 3200 most recent tweets of any public user, to get any more than that in one query you will have to pay.

現在抓推文! 使用get_timeline()函數可訪問任何公共用戶的3200條最新推文,以獲取除您將要支付的查詢之外的任何更多信息。

tweets <- get_timeline("TDataScience", n=3200, token=token)

There are 50 columns of data with 3200 rows stored in the variable “tweets” now. We primarily care about the columns text, favorite_count, and retweet_count, but you can explore what else you have to look at.

現在,變量“ tweets”中存儲了50列數據,其中3200行。 我們主要關心列文本,favorite_count和retweet_count,但是您可以探索其他內容。

刪除不需要的短語 (Removing Unwanted Phrases)

We’d also like to remove some things that are common to this domain, mainly links and twitter handles. We can use the gsub() function to replace occurrences of links and handles with something else, in our case we remove them by replacing them with empty strings. Below we pass the text column from one gsub() function to the next with the pipe operator, removing the urls and handles, ultimately saving them in a new column called clean_text.

我們還想刪除該域的一些常見內容,主要是鏈接和Twitter句柄。 我們可以使用gsub()函數將鏈接和句柄的出現替換為其他內容,在本例中,我們通過將它們替換為空字符串來刪除它們。 下面我們使用管道運算符將text列從一個gsub()函數傳遞到下一個gsub()函數,刪除url和handle,最終將它們保存在名為clean_text的新列中。

tweets$text %>% 
gsub("?(f|ht)(tp)(s?)(://)(.*)[.|/](.*)", "", .) %>%
gsub("@([A-Za-z0-9_]+)", "", .) -> tweets$clean_text

刪除停用詞 (Removing Stop Words)

Now we want to remove stop words from our clean_text column. Stop words are words that are not important to understanding the meaning of a passage. These are typically the most common words of a language, but there may be additional words you’d like to remove for a specific domain. In our task we might consider the word “data” to be trivial since almost every article will mention data.

現在我們要從clean_text列中刪除停用詞。 停用詞是對于理解段落的含義不重要的詞。 這些通常是一種語言中最常見的單詞,但是對于特定的域,您可能希望刪除其他單詞。 在我們的任務中,我們可能會認為“數據”一詞微不足道,因為幾乎每篇文章都會提到數據。

Tokenization is the process of splitting of text into sections. This could be by sentence, paragraph, word, or something else. In our case we will be using splitting by word, which will take our table of data and make into a table with one row for each word in each tweet. Below I select the columns of interest and then tokenize the words.

標記化是將文本分成多個部分的過程。 這可以是句子,段落,單詞或其他形式。 在我們的例子中,我們將使用按單詞拆分,這將獲取我們的數據表,并在每個推特中的每個單詞排成一行的表中。 在下面,我選擇感興趣的列,然后標記單詞。

tweets %>% 
select(clean_text, favorite_count, retweet_count) %>%
unnest_tokens(word, clean_text)

This leaves us with the table below, where the words “include”, “training”, and “operations”, were originally all part of the same row in the clean_text column.

這就留給我們下表,其中“ include”,“ training”和“ operations”一詞原本是clean_text列中同一行的一部分。

Image for post

Now we proceed by doing an anti-join with the stop_words data set from the tidytext package. This removes all the words that are part of both the tweets data set and the stop_words data set (essentially this removes the stop words from your data). The code for this is below.

現在,我們對tidytext包中的stop_words數據集進行反聯接。 這將刪除屬于tweets數據集和stop_words數據集的所有單詞(實質上,這將從數據中刪除停用詞)。 下面的代碼。

tweets %>% 
select(clean_text, favorite_count, retweet_count) %>%
unnest_tokens(word, clean_text) %>%
anti_join(stop_words)

獲得平均收藏夾和轉發 (Getting Average Favorites and Retweets)

Using the groub_by() and summarise() functions from the tidyverse, we can get the median number of favorites and retweets for each word in our data set. I choose to use median here to eliminate the effects that some outliers may have on our data.

使用tidyverse中的groub_by()和summarise()函數,我們可以獲得數據集中每個單詞的收藏夾和轉推的中位數。 我選擇在此處使用中位數來消除某些異常值可能會對我們的數據產生的影響。

tweets %>% 
select(clean_text, favorite_count, retweet_count) %>%
unnest_tokens(word, clean_text) %>%
anti_join(stop_words) %>%
group_by(word) %>%
summarise("Median Favorites" = median(favorite_count),
"Median Retweets" = median(retweet_count),
"Count" = n())

篩選結果 (Filtering Results)

We want to see the words that have the most favorites/retweets to inform us about what we should write about. But let’s consider the case where a word is only used once. For example, if there is one really popular article out their about data science applied to the geography of Michigan, we wouldn’t want this to bias us to writing articles about Michigan. To fix this, I filter out all the words that weren’t used in at least 4 tweets with the filter() function, and then sort the results with the arrange() function. Leaving us with our final bit of code.

我們希望看到最喜歡/轉發最多的單詞,以告知我們應該寫些什么。 但是,讓我們考慮一個單詞僅使用一次的情況。 例如,如果有一篇非常流行的文章將其應用于數據科學的文章應用于密歇根州,那么我們不希望這使我們偏向于撰寫有關密歇根州的文章。 為了解決這個問題,我使用filter()函數過濾掉了至少4條推文中未使用過的所有單詞,然后使用ranging()函數對結果進行排序。 剩下最后的代碼。

tweets %>% 
select(clean_text, favorite_count, retweet_count) %>%
unnest_tokens(word, clean_text) %>%
anti_join(stop_words) %>%
group_by(word) %>%
summarise("Median Favorites" = median(favorite_count),
"Median Retweets" = median(retweet_count),
"Count" = n()) %>%
arrange(desc(`Median Favorites`)) %>%
filter(`Count` > 4)

最終結果 (Final Results)

So if you are skipping to the end to see what the results are, or don’t want to run this code yourself, here are the results. These are the common words in Towards Data Science, ranked by how many favorites the tweet that contains that word usually gets.

因此,如果您跳到最后看看結果是什么,或者不想自己運行此代碼,則這里是結果。 這些是“邁向數據科學”中的常用詞,按包含該詞的推文通常獲得多少偏愛來排名。

  1. website — 84.5 favorites

    網站— 84.5收藏夾
  2. finance — 72 favorites

    金融— 72個收藏夾
  3. action — 66 favorites

    動作— 66個收藏夾
  4. matplotlib — 59.5 favorites

    matplotlib — 59.5個收藏夾
  5. plotting — 57 favorites

    繪圖— 57個收藏夾
  6. beautiful — 55.5 favorites

    美麗— 55.5收藏夾
  7. portfolio — 51 favorites

    投資組合— 51個收藏夾
  8. exploratory — 47 favorites

    探索— 47個收藏夾
  9. github — 46.5 favorites

    github — 46.5最喜歡的
  10. comprehensive — 46 favorites

    綜合— 46個收藏夾

Note: I did have to remove the word “James” here since apparently there is an author(s) out there who is very popular with that name. Congratulations, James(es)!

注意:我確實必須在這里刪除“ James”一詞,因為顯然那里有一位作者非常受歡迎。 恭喜,詹姆斯!

My advice now would be to write an article titled “A Comprehensive Guide to Creating Beautiful Financial Plots with Matplotlib” or something like that. You can repeat this process now for any other twitter user with a public account.

現在,我的建議是寫一篇標題為“使用Matplotlib創建漂亮的財務圖的綜合指南”或類似的文章。 您現在可以對具有公共帳戶的任何其他Twitter用戶重復此過程。

翻譯自: https://towardsdatascience.com/the-most-popular-towards-data-science-article-topics-on-twitter-2ecc512dd041

twitter數據分析

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388296.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388296.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388296.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

JAVA遇見HTML——JSP篇(JSP狀態管理)

案例&#xff1a;Cookie在登錄中的應用 URL編碼與解碼的工具類解決中文亂碼的問題&#xff0c;這個工具類在java.net.*包里 編碼&#xff1a;URLEncoder.encode(String s,String enc)//s&#xff1a;對哪個字符串進行編碼&#xff0c;enc&#xff1a;用的字符集&#xff08;例&…

PE文件講解

我們大家都知道&#xff0c;在Windows 9x、NT、2000下&#xff0c;所有的可執行文件都是基于Microsoft設計的一種新的文件格式Portable Executable File Format&#xff08;可移植的執行體&#xff09;&#xff0c;即PE格式。有一些時候&#xff0c;我們需要對這些可執行文件進…

easyui 布局之window和panel一起使用時,拉動window寬高時panel不跟隨一起變化

項目開發中布局是每一個組件都由最外層的window和內部的至少一個panel組成&#xff0c;其他的細小組件再依次放到panel中。 問題&#xff1a;當拉動外部的window時我們希望內部的panel的寬高也跟著變化&#xff0c;但是并沒有&#xff0c;尤其拉動其高度是更為明顯&#xff0c;…

是什么使波西米亞狂想曲成為杰作-數據科學視角

平均“命中率”是什么樣的 (What an Average ‘Hit’ looks like) Before we break the song down, let us have a brief analysis of what the greatest hits of all time had in common. I have picked 1500 songs ( charting hits ) right from the ’50s to the’10s, spre…

PE文件感染和內存駐留

這次&#xff0c;作者將和大家一起討論病毒的感染技術。另外&#xff0c;從本文開始&#xff0c;我們將陸續接觸到一些病毒的高級編碼技術。例如&#xff0c;內存駐留、EPO&#xff08;入口點模糊&#xff09;技術、加密技術、多態和變形等。通過這些高級技巧&#xff0c;你將進…

Python函數積累

評估函數eval() 去掉參數最外側引號并執行余下語句的函數 fun:將讓任何輸入的字符串轉換為python語句&#xff08;如"12132" -> 12132&#xff09;轉載于:https://www.cnblogs.com/LYluck/p/10376531.html

流行編程語言_編程語言的流行度排名

流行編程語言There has never been a unanimous agreement on what the most popular programming languages are, and probably never will be. Yet we believe that there is merit in trying to come up with ways to rank the popularity of programming languages. It hel…

Attributes.Add用途與用法

Attributes.Add("javascript事件","javascript語句");如&#xff1a;this.TextBox1.Attributes.add("onblue", "window.Label1.style.backgroundColor#000000;");this.TextBox1.Attributes.Add("onblur","this.style.d…

使用UIWebView加載網頁

1、使用UIWebView加載網頁 運行XCode 4.3&#xff0c;新建一個Single View Application&#xff0c;命名為WebViewDemo。 2、加載WebView 在ViewController.h添加WebView成員變量和在ViewController.m添加實現 [cpp] view plaincopyprint?#import <UIKit/UIKit.h> …

Java 開源庫精選(持續更新)

僅記錄親自使用和考慮使用的Apache Commons Commons IO - Commons IO 是一個幫助開發IO功能的實用程序庫 Commons Configuration - Commons Configuration 提供了一個通用配置界面&#xff0c;使Java應用程序可以從各種來源讀取配置數據。查看更多可重用、穩定的 Commons 組件S…

corba的興衰_數據科學薪酬的興衰

corba的興衰意見 (Opinion) 目錄 (Table of Contents) Introduction 介紹 Salary and Growth 薪資與增長 Summary 摘要 介紹 (Introduction) In the past five years, data science salary cumulative growth has varied between 12% in the United States, according to Glass…

hibernate的多表查詢

1.交叉連接 select * from A ,B 2.內連接 可以省略inner join 隱式內連接&#xff1a; select * from A,B where A.id B.aid; 顯式內連接&#xff1a; select * from A inner join B on A.id B.aid; 迫切內連接&#xff1a; 需要加上fetch關鍵字 內連接查詢兩者共有的屬性…

C# 讀取PE

最后分析結果會放在 一個DATASET里 ResourceDirectory這個TABLE 增加了 GUID列 為了好實現數結構 using System; using System.IO; using System.Data; using System.Collections; namespace PETEST { /// <summary> /// PeInfo 的摘要說明。 /// zgkesina.com …

10 個深惡痛絕的 Java 異常。。

異常是 Java 程序中經常遇到的問題&#xff0c;我想每一個 Java 程序員都討厭異常&#xff0c;一 個異常就是一個 BUG&#xff0c;就要花很多時間來定位異常問題。 什么是異常及異常的分類請看這篇文章&#xff1a;一張圖搞清楚 Java 異常機制。今天&#xff0c;棧長來列一下 J…

POJ 2777 - Count Color(線段樹區間更新+狀態壓縮)

題目鏈接 https://cn.vjudge.net/problem/POJ-2777 【題意】 有一個長度為 LLL 的區間 [1,L][1,L][1,L] &#xff0c;有 TTT 種顏色可以涂&#xff0c;有 QQQ 次操作&#xff0c;操作分兩種C A B CC \ A \ B \ CC A B C 把區間 [A,B][A,B][A,B] 涂成第 CCC 種顏色P A BP \ A \ …

如何實施成功的數據清理流程

干凈的數據是發現和洞察力的基礎。 如果數據很臟&#xff0c;您的團隊為分析&#xff0c;培養和可視化數據而付出的巨大努力完全是在浪費時間。 當然&#xff0c;骯臟的數據并不是新的。 它早在計算機變得普及之前就困擾著決策。 現在&#xff0c;計算機技術已普及到日常生活中…

nginx前端代理tomcat取真實客戶端IP

nginx前端代理tomcat取真實客戶端IP2011年12月14日? nginx? 暫無評論? 被圍觀 3,000 次使用Nginx作為反向代理時&#xff0c;Tomcat的日志記錄的客戶端IP就不在是真實的客戶端IP&#xff0c;而是Nginx代理的IP。要解決這個問題可以在Nginx配置一個新的Header&#xff0c;用來…

kubeadm安裝kubernetes 1.13.2多master高可用集群

1. 簡介 Kubernetes v1.13版本發布后&#xff0c;kubeadm才正式進入GA&#xff0c;可以生產使用,用kubeadm部署kubernetes集群也是以后的發展趨勢。目前Kubernetes的對應鏡像倉庫&#xff0c;在國內阿里云也有了鏡像站點&#xff0c;使用kubeadm部署Kubernetes集群變得簡單并且…

通才與專家_那么您準備聘請數據科學家了嗎? 通才還是專家?

通才與專家Throughout my 10-year career, I have seen people often spend their time and energy in passionate debates about what data science can deliver, and what data scientists do or do not do. I submit that these are the wrong questions to focus on when y…

ubuntu opengl 安裝

安裝相應的庫&#xff1a; sudo apt-get install build-essential libgl1-mesa-dev sudo apt-get install freeglut3-dev sudo apt-get install libglew-dev libsdl2-dev libsdl2-image-dev libglm-dev libfreetype6-dev 實例&#xff1a; #include "GL/glut.h" void…