<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/weather-forecast-with-regression-models-part-1/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://datascienceplus.com/weather-forecast-with-regression-models-part-1/"> R Programming – DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In this tutorial we are going to analyse a weather dataset to produce exploratory analysis and forecast reports based on regression models.<br>
We are going to take advantage of a public dataset which is part of the exercise datasets of the “Data Mining and Business Analytics with R” book (Wiley) written by Johannes Ledolter. In doing that, we are taking advantage of several R packages, caret package included.</p>
<p>The tutorial is going to be split in the following four parts:</p>
<blockquote><p>
1. Introducing the weather dataset and outlining its exploratory analysis<br>
2. Building logistic regression models for 9am, 3pm and late evening weather forecasts<br>
3. Tuning to improve accuracy of previously build models and show ROC plots<br>
4. Making considerations on “at-least” moderate rainfall scenarios and building additional models to predict further weather variables</p>
</blockquote>
<h3>R Packages</h3>
<p>Overall, we are going to take advantage of the following packages:</p>
<pre>
suppressPackageStartupMessages(library(knitr))
suppressPackageStartupMessages(library(caret))
suppressPackageStartupMessages(library(gmodels))
suppressPackageStartupMessages(library(lattice))
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(gridExtra))
suppressPackageStartupMessages(library(Kmisc))
suppressPackageStartupMessages(library(ROCR))
suppressPackageStartupMessages(library(corrplot))
</pre>
<h3>Exploratory Analysis</h3>
<p>The dataset under analysis is publicly available at: </p>
<p><a rel="nofollow" href="https://www.biz.uiowa.edu/faculty/jledolter/datamining/dataexercises.html" target="_blank">jledolter – datamining – data exercises</a></p>
<p>It contains daily observations from a single weather station. Let us start by loading the data and taking a look at.</p>
<pre>
set.seed(1023)
weather_data &lt;- read.csv(url(&quot;https://www.biz.uiowa.edu/faculty/jledolter/datamining/weather.csv&quot;), header = TRUE, sep = &quot;,&quot;, stringsAsFactors = TRUE)
kable(head(weather_data))
<em>|Date |Location | MinTemp| MaxTemp| Rainfall| Evaporation| Sunshine|WindGustDir | WindGustSpeed|WindDir9am |WindDir3pm | WindSpeed9am| WindSpeed3pm| Humidity9am| Humidity3pm| Pressure9am| Pressure3pm| Cloud9am| Cloud3pm| Temp9am| Temp3pm|RainToday | RISK_MM|RainTomorrow |
|:---------|:--------|-------:|-------:|--------:|-----------:|--------:|:-----------|-------------:|:----------|:----------|------------:|------------:|-----------:|-----------:|-----------:|-----------:|--------:|--------:|-------:|-------:|:---------|-------:|:------------|
|11/1/2007 |Canberra | 8.0| 24.3| 0.0| 3.4| 6.3|NW | 30|SW |NW | 6| 20| 68| 29| 1019.7| 1015.0| 7| 7| 14.4| 23.6|No | 3.6|Yes |
|11/2/2007 |Canberra | 14.0| 26.9| 3.6| 4.4| 9.7|ENE | 39|E |W | 4| 17| 80| 36| 1012.4| 1008.4| 5| 3| 17.5| 25.7|Yes | 3.6|Yes |
|11/3/2007 |Canberra | 13.7| 23.4| 3.6| 5.8| 3.3|NW | 85|N |NNE | 6| 6| 82| 69| 1009.5| 1007.2| 8| 7| 15.4| 20.2|Yes | 39.8|Yes |
|11/4/2007 |Canberra | 13.3| 15.5| 39.8| 7.2| 9.1|NW | 54|WNW |W | 30| 24| 62| 56| 1005.5| 1007.0| 2| 7| 13.5| 14.1|Yes | 2.8|Yes |
|11/5/2007 |Canberra | 7.6| 16.1| 2.8| 5.6| 10.6|SSE | 50|SSE |ESE | 20| 28| 68| 49| 1018.3| 1018.5| 7| 7| 11.1| 15.4|Yes | 0.0|No |
|11/6/2007 |Canberra | 6.2| 16.9| 0.0| 5.8| 8.2|SE | 44|SE |E | 20| 24| 70| 57| 1023.8| 1021.7| 7| 5| 10.9| 14.8|No | 0.2|No |
</em>
</pre>
<p>Metrics at specific Date and Location are given together with the RainTomorrow variable indicating if rain occurred on next day.</p>
<pre>
colnames(weather_data)
<em>[1] &quot;Date&quot; &quot;Location&quot; &quot;MinTemp&quot; &quot;MaxTemp&quot; &quot;Rainfall&quot; [6] &quot;Evaporation&quot; &quot;Sunshine&quot; &quot;WindGustDir&quot; &quot;WindGustSpeed&quot; &quot;WindDir9am&quot; [11] &quot;WindDir3pm&quot; &quot;WindSpeed9am&quot; &quot;WindSpeed3pm&quot; &quot;Humidity9am&quot; &quot;Humidity3pm&quot; [16] &quot;Pressure9am&quot; &quot;Pressure3pm&quot; &quot;Cloud9am&quot; &quot;Cloud3pm&quot; &quot;Temp9am&quot; [21] &quot;Temp3pm&quot; &quot;RainToday&quot; &quot;RISK_MM&quot; &quot;RainTomorrow&quot;
</em>
</pre>
<p><strong>The description of the variables is the following.</strong></p>
<blockquote><p>
Date: The date of observation (a date object).<br>
Location: The common name of the location of the weather station<br>
MinTemp: The minimum temperature in degrees centigrade<br>
MaxTemp: The maximum temperature in degrees centigrade<br>
Rainfall: The amount of rainfall recorded for the day in millimeters.<br>
Evaporation: Class A pan evaporation (in millimeters) during 24 h<br>
Sunshine: The number of hours of bright sunshine in the day<br>
WindGustDir: The direction of the strongest wind gust in the 24 h to midnight<br>
WindGustSpeed: The speed (in kilometers per hour) of the strongest wind gust in the 24 h to midnight<br>
WindDir9am: The direction of the wind gust at 9 a.m.<br>
WindDir3pm: The direction of the wind gust at 3 p.m.<br>
WindSpeed9am: Wind speed (in kilometers per hour) averaged over 10 min before 9 a.m.<br>
WindSpeed3pm: Wind speed (in kilometers per hour) averaged over 10 min before 3 p.m.<br>
Humidity9am: Relative humidity (in percent) at 9 am<br>
Humidity3pm: Relative humidity (in percent) at 3 pm<br>
Pressure9am: Atmospheric pressure (hpa) reduced to mean sea level at 9 a.m.<br>
Pressure3pm: Atmospheric pressure (hpa) reduced to mean sea level at 3 p.m.<br>
Cloud9am: Fraction of sky obscured by cloud at 9 a.m. This is measured in ”oktas,” which are a unit of eighths. It records how many eighths of the sky are obscured by cloud. A 0 measure indicates completely clear sky, while an 8 indicates that it is completely overcast<br>
Cloud3pm: Fraction of sky obscured by cloud at 3 p.m; see Cloud9am for a description of the values<br>
Temp9am: Temperature (degrees C) at 9 a.m.<br>
Temp3pm: Temperature (degrees C) at 3 p.m.<br>
RainToday: Integer 1 if precipitation (in millimeters) in the 24 h to 9 a.m. exceeds 1 mm, otherwise 0<br>
RISK_MM: The continuous target variable; the amount of rain recorded during the next day<br>
RainTomorrow: The binary target variable whether it rains or not during the next day
</p>
</blockquote>
<p>Looking then at the data structure, we discover the dataset includes a mix of numerical and categorical variables.</p>
<pre>
str(weather_data)
<em>> str(weather_data)
'data.frame':	366 obs. of 24 variables:
$ Date : Factor w/ 366 levels &quot;1/1/2008&quot;,&quot;1/10/2008&quot;,..: 63 74 85 87 88 89 90 91 92 64 ...
$ Location : Factor w/ 1 level &quot;Canberra&quot;: 1 1 1 1 1 1 1 1 1 1 ...
$ MinTemp : num 8 14 13.7 13.3 7.6 6.2 6.1 8.3 8.8 8.4 ...
$ MaxTemp : num 24.3 26.9 23.4 15.5 16.1 16.9 18.2 17 19.5 22.8 ...
$ Rainfall : num 0 3.6 3.6 39.8 2.8 0 0.2 0 0 16.2 ...
$ Evaporation : num 3.4 4.4 5.8 7.2 5.6 5.8 4.2 5.6 4 5.4 ...
$ Sunshine : num 6.3 9.7 3.3 9.1 10.6 8.2 8.4 4.6 4.1 7.7 ...
$ WindGustDir : Factor w/ 16 levels &quot;E&quot;,&quot;ENE&quot;,&quot;ESE&quot;,..: 8 2 8 8 11 10 10 1 9 1 ...
$ WindGustSpeed: int 30 39 85 54 50 44 43 41 48 31 ...
$ WindDir9am : Factor w/ 16 levels &quot;E&quot;,&quot;ENE&quot;,&quot;ESE&quot;,..: 13 1 4 15 11 10 10 10 1 9 ...
$ WindDir3pm : Factor w/ 16 levels &quot;E&quot;,&quot;ENE&quot;,&quot;ESE&quot;,..: 8 14 6 14 3 1 3 1 2 3 ...
$ WindSpeed9am : int 6 4 6 30 20 20 19 11 19 7 ...
$ WindSpeed3pm : int 20 17 6 24 28 24 26 24 17 6 ...
$ Humidity9am : int 68 80 82 62 68 70 63 65 70 82 ...
$ Humidity3pm : int 29 36 69 56 49 57 47 57 48 32 ...
$ Pressure9am : num 1020 1012 1010 1006 1018 ...
$ Pressure3pm : num 1015 1008 1007 1007 1018 ...
$ Cloud9am : int 7 5 8 2 7 7 4 6 7 7 ...
$ Cloud3pm : int 7 3 7 7 7 5 6 7 7 1 ...
$ Temp9am : num 14.4 17.5 15.4 13.5 11.1 10.9 12.4 12.1 14.1 13.3 ...
$ Temp3pm : num 23.6 25.7 20.2 14.1 15.4 14.8 17.3 15.5 18.9 21.7 ...
$ RainToday : Factor w/ 2 levels &quot;No&quot;,&quot;Yes&quot;: 1 2 2 2 2 1 1 1 1 2 ...
$ RISK_MM : num 3.6 3.6 39.8 2.8 0 0.2 0 0 16.2 0 ...
$ RainTomorrow : Factor w/ 2 levels &quot;No&quot;,&quot;Yes&quot;: 2 2 2 2 1 1 1 1 2 1 ...
</em>
</pre>
<p>We have available 366 records:</p>
<pre>
(n &lt;- nrow(weather_data))
<em>[1] 366
</em>
</pre>
<p>which spans the following timeline:</p>
<pre>
c(as.character(weather_data$Date[1]), as.character(weather_data$Date[n]))
<em>[1] &quot;11/1/2007&quot; &quot;10/31/2008&quot;
</em>
</pre>
<p>We further notice that RISK_MM relation with the RainTomorrow variable is the following.</p>
<pre>
all.equal(weather_data$RISK_MM > 1, weather_data$RainTomorrow == &quot;Yes&quot;)
<em>[1] TRUE
</em>
</pre>
<p>The Rainfall variable and the RainToday are equivalent according to the following relationship (as anticipated by the Rainfall description).</p>
<pre>
all.equal(weather_data$Rainfall > 1, weather_data$RainToday == &quot;Yes&quot;)
<em>[1] TRUE
</em>
</pre>
<p>To make it more challenging, we decide to take RISK_MM, RainFall and RainToday out, and determine a new dataset as herein depicted.</p>
<pre>
weather_data2 &lt;- subset(weather_data, select = -c(Date, Location, RISK_MM, Rainfall, RainToday))
colnames(weather_data2)
<em>[1] &quot;MinTemp&quot; &quot;MaxTemp&quot; &quot;Evaporation&quot; &quot;Sunshine&quot; &quot;WindGustDir&quot; &quot;WindGustSpeed&quot;
[7] &quot;WindDir9am&quot; &quot;WindDir3pm&quot; &quot;WindSpeed9am&quot; &quot;WindSpeed3pm&quot; &quot;Humidity9am&quot; &quot;Humidity3pm&quot; [13] &quot;Pressure9am&quot; &quot;Pressure3pm&quot; &quot;Cloud9am&quot; &quot;Cloud3pm&quot; &quot;Temp9am&quot; &quot;Temp3pm&quot; [19] &quot;RainTomorrow&quot; </em>
</pre>
<pre>
(cols_withNa &lt;- apply(weather_data2, 2, function(x) sum(is.na(x))))
<em>MinTemp MaxTemp Evaporation Sunshine WindGustDir WindGustSpeed WindDir9am 0 0 0 3 3 2 31 WindDir3pm WindSpeed9am WindSpeed3pm Humidity9am Humidity3pm Pressure9am Pressure3pm 1 7 0 0 0 0 0 Cloud9am Cloud3pm Temp9am Temp3pm RainTomorrow 0 0 0 0 0 </em>
</pre>
<p>Look at the NA’s counts associated to WindDir9am. If WindDir9am were a not significative predictor for RainTomorrow, we could take such data column out and increased the complete cases count. When dealing with the categorical variable analysis we determine if that is possible. For now, we consider records without NA’s values.</p>
<pre>
weather_data3 &lt;- weather_data2[complete.cases(weather_data2),]
</pre>
<h3>Categorical Variable Analysis</h3>
<pre>
factor_vars &lt;- names(which(sapply(weather_data3, class) == &quot;factor&quot;))
factor_vars &lt;- setdiff(factor_vars, &quot;RainTomorrow&quot;)
chisq_test_res &lt;- lapply(factor_vars, function(x) { 
  chisq.test(weather_data3[,x], weather_data3[, &quot;RainTomorrow&quot;], simulate.p.value = TRUE)
  })
names(chisq_test_res) &lt;- factor_vars
chisq_test_res
<em>$WindGustDir
Pearson's Chi-squared test with simulated p-value (based on 2000 replicates)
data: weather_data3[, x] and weather_data3[, &quot;RainTomorrow&quot;]
X-squared = 35.833, df = NA, p-value = 0.001999
$WindDir9am
Pearson's Chi-squared test with simulated p-value (based on 2000 replicates)
data: weather_data3[, x] and weather_data3[, &quot;RainTomorrow&quot;]
X-squared = 23.813, df = NA, p-value = 0.06547
$WindDir3pm
Pearson's Chi-squared test with simulated p-value (based on 2000 replicates)
data: weather_data3[, x] and weather_data3[, &quot;RainTomorrow&quot;]
X-squared = 9.403, df = NA, p-value = 0.8636
</em>
</pre>
<p>Above shown Chi-squared p-value results tell us that RainTomorrow values depend upon WindGustDir (we reject the null hypothesis that RainTomorrow does not depend upon the WindGustDir). We reject the null-hypothesis for WindDir9am and WindDir3pm as well. We therefore expect to take advantage of WindGustDir as predictor and not to consider WindDir9am and WindDir3pm for such purpose.</p>
<p>It is also possible to obtain a visual understanding of the significativeness of such categorical variables by taking advantage of barcharts with the cross table row proportions as input.</p>
<pre>
barchart_res &lt;- lapply(factor_vars, function(x) { 
  title &lt;- colnames(weather_data3[,x, drop=FALSE])
  wgd &lt;- CrossTable(weather_data3[,x], weather_data3$RainTomorrow, prop.chisq=F)
  barchart(wgd$prop.row, stack=F, auto.key=list(rectangles = TRUE, space = &quot;top&quot;, title = title))
})
names(barchart_res) &lt;- factor_vars
barchart_res$WindGustDir
</pre>
<p>Barchart of WindGustDir<br>
<a rel="nofollow" href="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/05/WindGustDir.png?ssl=1" target="_blank"><img sizes="(max-width: 805px) 100vw, 805px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/05/WindGustDir.png?w=450&ssl=1" alt="" class="wp-image-6649" data-recalc-dims="1"></a></p>
<pre>barchart_res$WindDir9am</pre>
<p>Barchart of WindDir9am<br>
<a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/05/WindDir9am.png?ssl=1" target="_blank"><img sizes="(max-width: 849px) 100vw, 849px" src="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/05/WindDir9am.png?w=450&ssl=1" alt="" class="wp-image-6651" data-recalc-dims="1"></a></p>
<pre>barchart_res$WindDir3pm</pre>
<p>Barchart of WindDir3pm<br>
<a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/05/WindDir3pm.png?ssl=1" target="_blank"><img sizes="(max-width: 840px) 100vw, 840px" src="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/05/WindDir3pm.png?w=450&ssl=1" alt="" class="wp-image-6652" data-recalc-dims="1"></a></p>
<p>Being WindDir9am not a candidate predictor and having got more than 30 NA’s values, we decide to take it out. As a consequence, we have increased the number of NA-free records from 328 to 352. Same for WindDir3pm.</p>
<pre>
weather_data4 &lt;- subset(weather_data2, select = -c(WindDir9am, WindDir3pm))
weather_data5 &lt;- weather_data4[complete.cases(weather_data4),]
colnames(weather_data5)
<em>[1] &quot;MinTemp&quot; &quot;MaxTemp&quot; &quot;Evaporation&quot; &quot;Sunshine&quot; &quot;WindGustDir&quot; [6] &quot;WindGustSpeed&quot; &quot;WindSpeed9am&quot; &quot;WindSpeed3pm&quot; &quot;Humidity9am&quot; &quot;Humidity3pm&quot; [11] &quot;Pressure9am&quot; &quot;Pressure3pm&quot; &quot;Cloud9am&quot; &quot;Cloud3pm&quot; &quot;Temp9am&quot; [16] &quot;Temp3pm&quot; &quot;RainTomorrow&quot; </em>
</pre>
<p>So, we end up with a dataset made up of 16 potential predictors, one of those is a categorical variable (WindGustDir) and 15 are quantitative.</p>
<h2>Quantitative Variable Analysis</h2>
<p>In this section, we carry on the exploratory analysis of quantitative variables. We start first by a visualization of the correlation relationship among variables.</p>
<pre>
factor_vars &lt;- names(which(sapply(weather_data5, class) == &quot;factor&quot;))
numeric_vars &lt;- setdiff(colnames(weather_data5), factor_vars)
numeric_vars &lt;- setdiff(numeric_vars, &quot;RainTomorrow&quot;)
numeric_vars
numeric_vars_mat &lt;- as.matrix(weather_data5[, numeric_vars, drop=FALSE])
numeric_vars_cor &lt;- cor(numeric_vars_mat)
corrplot(numeric_vars_cor)
</pre>
<p><a rel="nofollow" href="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/05/corrplot.png?ssl=1" target="_blank"><img sizes="(max-width: 779px) 100vw, 779px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/05/corrplot.png?w=450&ssl=1" alt="" class="wp-image-6656" data-recalc-dims="1"></a></p>
<p>By taking a look at above shown correlation plot, we can state that:<br>
– Temp9am strongly positive correlated with MinTemp<br>
– Temp9am strongly positive correlated with MaxTemp<br>
– Temp9am strongly positive correlated with Temp3pm<br>
– Temp3pm strongly positive correlated with MaxTemp<br>
– Pressure9am strongly positive correlated with Pressure3pm<br>
– Humidity3pm strongly negative correlated with Sunshine<br>
– Cloud9am strongly negative correlated with Sunshine<br>
– Cloud3pm strongly negative correlated with Sunshine</p>
<p>The pairs plot put in evidence if any relationship among variables is in place, such as a linear relationship.</p>
<pre>
pairs(weather_data5[,numeric_vars], col=weather_data5$RainTomorrow)
</pre>
<p><a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2017/05/pairplot.png?ssl=1" target="_blank"><img sizes="(max-width: 1200px) 100vw, 1200px" src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2017/05/pairplot.png?w=450&ssl=1" alt="" class="wp-image-6660" data-recalc-dims="1"></a></p>
<p>Visual analysis, put in evidence a linear relationship among the following variable pairs:</p>
<ul>
MinTemp and MaxTemp<br>
MinTemp and Evaporation<br>
MaxTemp and Evaporation<br>
Temp9am and MinTemp<br>
Temp3pm and MaxTemp<br>
Pressure9am and Pressure3pm<br>
Humidity9am and Humidity3pm<br>
WindSpeed9am and WindGustSpeed<br>
WindSpeed3pm and WindGustSpeed</ul>
<p>Boxplots and density plots give a visual understanding of the significativeness of a predictor by looking how much are overlapping the predictor values set depending on the variable to be predicted (RainTomorrow).</p>
<pre>
gp &lt;- invisible(lapply(numeric_vars, function(x) { 
  ggplot(data=weather_data5, aes(x= RainTomorrow, y=eval(parse(text=x)), col = RainTomorrow)) + geom_boxplot() + xlab(&quot;RainTomorrow&quot;) + ylab(x) + ggtitle(&quot;&quot;) + theme(legend.position=&quot;none&quot;)}))
grob_plots &lt;- invisible(lapply(chunk(1, length(gp), 4), function(x) {
  marrangeGrob(grobs=lapply(gp[x], ggplotGrob), nrow=2, ncol=2)}))
grob_plots
</pre>
<p><a rel="nofollow" href="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/05/boxplot_1.png?ssl=1" target="_blank"><img sizes="(max-width: 874px) 100vw, 874px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/05/boxplot_1.png?w=450&ssl=1" alt="" class="wp-image-6662" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2017/05/boxplot_2.png?ssl=1" target="_blank"><img sizes="(max-width: 854px) 100vw, 854px" src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2017/05/boxplot_2.png?w=450&ssl=1" alt="" class="wp-image-6664" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/05/boxplot_3.png?ssl=1" target="_blank"><img sizes="(max-width: 893px) 100vw, 893px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/05/boxplot_3.png?w=450&ssl=1" alt="" class="wp-image-6665" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/05/boxplot_4.png?ssl=1" target="_blank"><img sizes="(max-width: 882px) 100vw, 882px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/05/boxplot_4.png?w=450&ssl=1" alt="" class="wp-image-6666" data-recalc-dims="1"></a></p>
<pre>
gp &lt;- invisible(lapply(numeric_vars, function(x) { 
  ggplot(data=weather_data5, aes(x=eval(parse(text=x)), col = RainTomorrow)) + geom_density() + xlab(x) + ggtitle(paste(x, &quot;density&quot;, sep= &quot; &quot;))}))
grob_plots &lt;- invisible(lapply(chunk(1, length(gp), 4), function(x) {
  marrangeGrob(grobs=lapply(gp[x], ggplotGrob), nrow=2, ncol=2)}))
grob_plots
</pre>
<p><a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/05/densityplot_1.png?ssl=1" target="_blank"><img sizes="(max-width: 880px) 100vw, 880px" src="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/05/densityplot_1.png?w=450&ssl=1" alt="" class="wp-image-6668" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/05/densityplot_2.png?ssl=1" target="_blank"><img sizes="(max-width: 925px) 100vw, 925px" src="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/05/densityplot_2.png?w=450&ssl=1" alt="" class="wp-image-6669" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2017/05/densityplot_3.png?ssl=1" target="_blank"><img sizes="(max-width: 844px) 100vw, 844px" src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2017/05/densityplot_3.png?w=450&ssl=1" alt="" class="wp-image-6671" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/05/densityplot_4.png?ssl=1" target="_blank"><img sizes="(max-width: 884px) 100vw, 884px" src="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/05/densityplot_4.png?w=450&ssl=1" alt="" class="wp-image-6670" data-recalc-dims="1"></a></p>
<p>From all those plots, we can state that Humidity3pm, Pressure9am, Pressure3pm, Cloud9am, Cloud3pm and Sunshine are predictors to be considered.</p>
<p>Ultimately, we save the dataset currently under analysis for the prosecution of this tutorial.</p>
<pre>
write.csv(weather_data5, file=&quot;weather_data5.csv&quot;, sep=&quot;,&quot;, row.names=FALSE)
</pre>
<h2>Conclusions</h2>
<p>Exploratory analysis has highlighted interesting relationship across variables. Such preliminary results give us hints for predictors selection and will be considered in the prosecution of this analysis.</p>
<p>If you have any questions, please feel free to comment below.</p>
<h3>References</h3>
<ul>
<a rel="nofollow" href="http://eu.wiley.com/WileyCDA/WileyTitle/productCd-111844714X.html" target="_blank">Data Mining and Business Analytics with R, Johannes Ledolter, Wiley</a></ul>
<ul></ul>
<p><strong>
<p>Related Post</p>
<p>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/weighted-linear-support-vector-machine/" title="Permanent Link toWeighted Linear Support Vector Machine" target="_blank">Weighted Linear Support Vector Machine</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/logistic-regression-regularized-with-optimization/" title="Permanent Link toLogistic Regression Regularized with Optimization" target="_blank">Logistic Regression Regularized with Optimization</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/analytical-and-numerical-solutions-to-linear-regression-problems/" title="Permanent Link toAnalytical and Numerical Solutions to Linear Regression Problems" target="_blank">Analytical and Numerical Solutions to Linear Regression Problems</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/how-to-create-a-loop-to-run-multiple-regression-models/" title="Permanent Link toHow to create a loop to run multiple regression models" target="_blank">How to create a loop to run multiple regression models</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/regression-model-with-auto-correlated-errors-part-3-some-astrology/" title="Permanent Link toRegression model with auto correlated errors – Part 3, some astrology" target="_blank">Regression model with auto correlated errors – Part 3, some astrology</a></li>
</ol></strong>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://datascienceplus.com/weather-forecast-with-regression-models-part-1/"> R Programming – DataScience+</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...

	<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/L_zLW_cakBE" height="1"></a></div>