Modélisation de classification

Introduction au Natural Language Processing en R

Kasey Jones

Research Data Scientist

Récapitulatif des étapes

  1. Nettoyer/préparer les données

    • Filtrer les phrases sur Boxer/Napoléon
    • Créer des tokens nettoyés des mots
    • Créer une matrice document-termes pondérée par TF-IDF
  2. Créer des jeux d'entraînement et de test

  3. Entraîner un modèle sur le jeu d'entraînement
  4. Rapporter l'exactitude sur le jeu de test
Introduction au Natural Language Processing en R

Étape 2 : scinder les données

set.seed(1111)
sample_size <- floor(0.80 * nrow(animal_matrix))
train_ind <- sample(nrow(animal_matrix), size = sample_size)
train <- animal_matrix[train_ind, ]
test <- animal_matrix[-train_ind, ]
Introduction au Natural Language Processing en R

Modèles de forêts aléatoires

Introduction au Natural Language Processing en R

Exemple de classification

library(randomForest)
rfc <- randomForest(x = as.data.frame(as.matrix(train)), 
                    y = animal_sentences$Name[train_ind], nTree = 50)
rfc
Call:
 randomForest(...
        OOB estimate of  error rate: 23.33%
Confusion matrix:
         boxer napoleon class.error
boxer       37       20   0.3508772
napoleon     8       55   0.1269841
Introduction au Natural Language Processing en R

La matrice de confusion

Call:
 randomForest(...
        OOB estimate of  error rate: 23.33%
Confusion matrix:
         boxer napoleon class.error
boxer       37       20   0.3508772
napoleon     8       55   0.1269841

Exactitude : (37 + 55) / (37 + 20 + 8 + 55) = 76 %

Introduction au Natural Language Processing en R

Prédictions sur le jeu de test

y_pred <- predict(rfc, newdata = as.data.frame(as.matrix(test)))
table(animal_sentences[-train_ind, ]$Name, y_pred)
          y_pred
           boxer napoleon
  boxer       14        4
  napoleon     2       10
  • Exactitude pour boxer : 14/18
  • Exactitude pour napoléon : 10/12
  • Exactitude globale : 24/30 = 80 %
Introduction au Natural Language Processing en R

Entraînez-vous à la classification

Introduction au Natural Language Processing en R

Preparing Video For Download...