/
03-predict.R
35 lines (27 loc) · 989 Bytes
/
03-predict.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#====================================================================
# Compute predicted values on any set of tweets
# Author: Pablo Barbera
# Last update: 2018/08/19
#====================================================================
library(quanteda)
source("functions.R")
# loading classifier and dfm
load("data/lasso-classifier.rdata")
load("data/dfm-file.rdata")
# predicting a single tweet
text <- "politicians are morons"
predict_incivility(text="politicians are awful",
old_dfm = dfm,
classifier = lasso)
# predicting multiple tweets
df <- data.frame(
text = c( # no incivility
"I respect your opinion", "you are an example of leadership",
# some incivility
"oh shut up", "you are a traitor",
# very uncivil
"what an asshole and a loser", "spineless piece of shit")
)
predict_incivility(df$text,
old_dfm = dfm,
classifier = lasso)