-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFake News.R
42 lines (25 loc) · 1.28 KB
/
Fake News.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
33
34
35
36
37
38
39
40
41
42
# Fake News
## Loading the Libraries
library(rpart)
library(rpart.plot)
setwd('./Kaggle')
### Reading the Fake News Dataset
fake <- read.csv('fake.csv')
print(table(fake$type))
head(fake)
### Checking for NA Values
any(is.na(fake))
### Running the Analysis
mini_model <- rpart(formula = type ~ ord_in_thread + language + country + spam_score + replies_count + participants_count + likes + comments + shares,
data = fake,
method = "class", # Classification
parms = list(split = "information"), # Use Information Gain as splitting criterion
control = rpart.control(cp = 0.01, # Minimum loss decrease complexity param
maxcompete = 3, # Competition by split for debugging
maxsurrogate = 3, # Competition per surrogate for debugging
xval = 20, # 10 cross-validation
maxdepth = 4)) # Maximum Depth for easy interpretation
plotcp(mini_model)
### Decision Tree
rpart.plot(mini_model, main = "Decision Tree", box.palette = list("Gy", "Gn", "Bu", "Bn", "Or", "Rd", "Gy", "Pu"))
print(summary(mini_model))