-
Notifications
You must be signed in to change notification settings - Fork 0
/
forestfires.R
73 lines (54 loc) · 1.7 KB
/
forestfires.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
library('dplyr')
library('ggplot2')
ff <- read.csv("http://archive.ics.uci.edu/ml/machine-learning-databases/forest-fires/forestfires.csv")
# Filter and take a log of area
ff <- ff %>%
filter(area > 0) %>%
mutate(logArea = log(area))
# Create a histogram of logArea
ff %>%
filter(area > 0) %>%
mutate(logArea = log(area)) %>%
ggplot(aes(x = logArea)) +
geom_histogram()
# Create boxplots
ggplot(ff, aes(x = as.factor(X), y=logArea)) +
geom_boxplot()
# Create correlation matrix
numericFF <- ff %>%
select(-X, -Y, -month, -day, -area)
M <- round(cor(numericFF), 2)
# Recode the month variable
#forestfires$season <- rep("spring", 270)
for (i in 1:270){
if(ff$month[i] %in% c("dec", "jan", "feb"))
ff$season[i] <- "winter"
else if (ff$month[i] %in% c("sep", "oct", "nov"))
ff$season[i] <- "fall"
else if (ff$month[i] %in% c("jun", "jul", "aug"))
ff$season[i] <- "summer"
else
ff$season[i] <- "spring"
}
# Create a histogram to check the distribution of values faceted by season.
ggplot(ff, aes(x = logArea)) +
geom_histogram() +
facet_grid(~as.factor(season))
# Plot scatter plots
ggplot(ff, aes(x = FFMC, y = logArea)) +
geom_point()
# Extract only numeric variables
nFF <- ff %>%
select(-X, -Y, -month, -day, -season, -area)
# Regression
ggplot(forestfires, aes(x=FFMC, y=logArea)) +
geom_point() +
geom_abline(intercept = mean(logArea), slope = 0) +
geom_smooth(method="lm", se=FALSE)
ggplot(forestfires, aes(x=FFMC, y=logArea)) +
geom_point() +
geom_abline(intercept = 3.54, slope = -0.019)
ggplot(forestfires, aes(x=FFMC, y=logArea)) +
geom_point() +
geom_smooth(method = "lm", se=FALSE)
#### APPROACH 2: log(area + 1) then remove zeros