Modélisation de sujets pour des tweets

Analyzing Social Media Data in R

Vivek Vijayaraghavan

Data Science Coach

Aperçu de la leçon

  • Principes de la modélisation de sujets
  • Créer une matrice termes-documents (DTM)
  • Construire un modèle de sujets à partir de la DTM
Analyzing Social Media Data in R

Sujet et document

Définition d'un sujet et exemple

Analyzing Social Media Data in R

Sujet et document

Définition d'un document et exemple

Analyzing Social Media Data in R

Modélisation de sujets

  • Découverte automatique de sujets
  • Extraire les thèmes clés de grands jeux de données
  • Résumer rapidement une masse d'infos en sujets
Analyzing Social Media Data in R

Comment LDA fonctionne

  • Algorithme Latent Dirichlet Allocation pour la modélisation de sujets

Fonctionnement de LDA

Analyzing Social Media Data in R

Comment LDA fonctionne

Fonctionnement de LDA

Analyzing Social Media Data in R

Comment LDA fonctionne

Fonctionnement de LDA

Analyzing Social Media Data in R

Matrice termes-documents (DTM)

  • Créer une matrice termes-documents
  • La DTM est une représentation matricielle d'un corpus
  • Les documents sont en lignes et les mots/termes en colonnes

Matrice termes-documents ou DTM

Analyzing Social Media Data in R

Créer une matrice termes-documents

# Create a document term matrix
dtm <- DocumentTermMatrix(twt_corpus_refined)
Analyzing Social Media Data in R

Créer une matrice termes-documents

# Inspect the DTM
inspect(dtm)
Analyzing Social Media Data in R

Créer une matrice termes-documents

<<DocumentTermMatrix (documents: 1000, terms: 5079)>>
Non-/sparse entries: 12862/5066138
Sparsity           : 100%
Maximal term length: 29
Weighting          : term frequency (tf)
Sample             :
     Terms
Docs    california child diabetes fat food health people ranks rates weight
  131          0     0        0   0    0      0      0     0     0      0
  161          0     0        0   2    0      0      0     0     0      1
  295          0     0        0   0    1      0      1     0     0      0
  418          0     0        0   0    0      0      0     0     1      0
  604          0     0        1   0    0      1      0     0     0      0
Analyzing Social Media Data in R

Préparer la DTM

  • Filtrer la DTM pour ne garder que les lignes dont la somme est > 0
# Find the sum of word counts in each Document 
rowTotals <- apply(dtm , 1, sum)
# Select rows from DTM with row totals greater than zero
tweet_dtm_new <- dtm[rowTotals> 0, ]
Analyzing Social Media Data in R

Construire le modèle de sujets

  • Créer le modèle de sujets avec la fonction LDA()
# Build the topic model
library(topicmodels)
lda_5 <- LDA(tweet_dtm_new, k = 5)
Analyzing Social Media Data in R

Construire le modèle de sujets

  • 5 sujets extraits du corpus de tweets
# View top 10 terms in the topic model
top_10terms <- terms(lda_5,10)
top_10terms
Analyzing Social Media Data in R

Afficher les 10 termes principaux du modèle

     Topic 1        Topic 2        Topic 3     Topic 4      Topic 5   
 [1,] "disease"      "people"       "black"     "child"      "weight"  
 [2,] "health"       "health"       "fat"       "rates"      "diet"    
 [3,] "cancer"       "diabetes"     "trump"     "ranks"      "food"    
 [4,] "meghanmccain" "overweight"   "childhood" "california" "diabetes"
 [5,] "realcandaceo" "fat"          "health"    "fat"        "health"  
 [6,] "food"         "meghanmccain" "professor" "eat"        "bmi"     
 [7,] "risk"         "realcandaceo" "gender"    "people"     "problem" 
 [8,] "heart"        "body"         "studies"   "epidemic"   "eating"  
 [9,] "weight"       "weight"       "healthy"   "health"     "disease" 
[10,] "diabetes"     "obese"        "problem"   "healthy"    "family"
  • Un programme de prise en charge de l'obésité peut s'articuler autour d'un sujet central
Analyzing Social Media Data in R

Passons à la pratique !

Analyzing Social Media Data in R

Preparing Video For Download...