Below are the solutions to these exercises on density-based clustering. #################### # # # Exercise 1 # # # #################### df <- iris[, -ncol(iris)] #################### # # # Exercise 2 # # # #################### df <- scale(df) df <- as.data.frame(df) #################### # # # Exercise 3 # # # #################### require(dbscan) kNNdistplot(df, k = 5) […]

## Density-Based Clustering Exercises

Density-based clustering is a technique that allows to partition data into groups with similar characteristics (clusters) but does not require specifying the number of those groups in advance. In density-based clustering, clusters are defined as dense regions of data points separated by low-density regions. Density is measured by the number of data points within some […]

## Forecasting: ARIMAX Model Exercises (Part-5)

The standard ARIMA (autoregressive integrated moving average) model allows to make forecasts based only on the past values of the forecast variable. The model assumes that future values of a variable linearly depend on its past values, as well as on the values of past (stochastic) shocks. The ARIMAX model is an extended version of […]

## Forecasting: ARIMAX Model Exercises (Part-5) Solutions

Below are the solutions to these exercises on forecasting with the extended ARIMA model. #################### # # # Exercise 1 # # # #################### require(ggplot2) require(gridExtra) df <- read.csv("Icecream.csv") p1 <- ggplot(df, aes(x = X, y = cons)) + ylab("Consumption") + xlab("") + geom_line() + expand_limits(x = 0, y = 0) p2 <- ggplot(df, aes(x […]

## Forecasting: Multivariate Regression Exercises (Part-4) Solutions

Below are the solutions to these exercises on forecasting with multivariate regression. #################### # # # Exercise 1 # # # #################### auto <- read.csv("vehicles.csv") plot(auto$sales, type = "n", ylim = c(0, 5000), ylab = "Sales, ‘000 units", xlab = "Period", main = "US light vehicle sales in 1976-2016") lines(auto$sales) #################### # # # Exercise […]

## Forecasting: Multivariate Regression Exercises (Part-4)

In the previous exercises of this series, forecasts were based only on an analysis of the forecast variable. Another approach to forecasting is to use external variables, which serve as predictors. This set of exercises focuses on forecasting with the standard multivariate linear regression. Running regressions may appear straightforward but this method of forecasting is […]

## Forecasting: Exponential Smoothing Exercises (Part-3) Solutions

Below are the solutions to these exercises on forecasting with exponential smoothing. #################### # # # Exercise 1 # # # #################### df <- read.csv("unemployment.csv") unempl <- ts(df, start = c(2012, 1), frequency = 12) plot(unempl) #################### # # # Exercise 2 # # # #################### require(forecast) fcast_ses <- ses(unempl, h = 12) plot(fcast_ses) #################### […]

## Forecasting: Exponential Smoothing Exercises (Part-3)

Exponential smoothing is a method of finding patterns in time series, which can be used to make forecasts. In its simple form, exponential smoothing is a weighted moving average: each smoothed value is a weighted average of all past time series values (with weights decreasing exponentially from the most recent to the oldest values). In […]

## Forecasting: Linear Trend and ARIMA Models Exercises (Part-2) Solutions

Below are the solutions to these exercises on forecasting using linear models. #################### # # # Exercise 1 # # # #################### df <- read.csv("ecommerce.csv") series <- ts(df, frequency = 4, start = c(1999, 4)) plot(series) #################### # # # Exercise 2 # # # #################### require(forecast) fcast_naive <- naive(series, h = 8) #################### # […]

## Forecasting: Linear Trend and ARIMA Models Exercises (Part-2)

There are two main approaches to time series forecasting. One of them is to find persistent patterns in a time series itself, and extrapolate those patterns. Another approach is to discover how a series depend on other variables, which serve as predictors. This set of exercises focuses on the first approach, while the second one […]