Classification and Regression, Part 1 - Exercise¶

In [ ]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.pyplot as plt

Exercise 1. Univariate Classification¶


About the data¶


The dataset you will use for today exercise is a modified version of Computers https://www.timeseriesclassification.com/description.php?Dataset=Computers

These problems were taken from data recorded as part of government sponsored study called Powering the Nation. The intention was to collect behavioural data about how consumers use electricity within the home to help reduce the UK's carbon footprint. The data contains readings from 251 households, sampled in two-minute intervals over a month. Each series is length 720 (24 hours of readings taken every 2 minutes). Classes are Desktop and Laptop.


Read the data¶

Load the numpy files X_train_computers.npy, X_test_computers.npy, y_train_computers.npy, y_test_computers.npy

In [ ]:
 

Data Understanding/Preparation¶

Try to understand the data first... Plot some of the data, what do you see? Ask yourself a few questions:

  • How many classes are there? Are the classes balanced?
  • Are there any missing values?
  • Are there outlier values? (hint: make a boxplot of all the data)

In [ ]:
 

How many classes are there? Are the classes balanced?¶

In [ ]:
 

Are there any missing values?¶

In [ ]:
 

Are there any outlier values?¶

In [ ]:
 

Deal with the problems you found in the previous step. E.g., remove missing values, remove outliers, etc.¶

In [ ]:
from sktime.transformations.series.impute import Imputer
In [ ]:
 

Classification¶

After you removed the main problems in the data, you can start the classification process. Does the dataset need further preprocessing (normalization maybe)? If so, do it. Use the LabelEncoder to transform the target variable in a numerical format.

Goal¶

Your goal here is to find the best possible classification pipeline to predict the class of the computers dataset. You can use any classifier you saw in the course up to now.

Hyperparameter tuning¶

Try to find the best hyperparameters for your model. You can a validation set, cross validation or a GridSearchCV or RandomizedSearchCV for this task.

Evaluation¶

Don't overfit the test set! Only once you think you found the best model, test performance on the test set. Find the model that has the highest ROC AUC score.

In [ ]:
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import GridSearchCV

Label Encoding¶

In [ ]:
from sklearn.preprocessing import LabelEncoder
In [ ]:
 

How does a dummy classifier perform?¶

In [ ]:
from sktime.classification.dummy import DummyClassifier
In [ ]:
dummy = DummyClassifier()
In [ ]:
cross_val_score(dummy, X_train, y_train, cv=5, scoring="roc_auc").mean()
In [ ]:
 
In [ ]:
 

Evaluation¶

let's train the best model on the whole training set and evaluate it on the test set

In [ ]:
 

Exercise 2. Multivariate Regression¶


About the data¶

The goal of this dataset is to predict total energy usage in kWh of a house. This dataset contains 138 time series obtained from the Appliances Energy Prediction dataset from the UCI repository. The time series has 24 dimensions. This includes temperature and humidity measurements of 9 rooms in a house, monitored with a ZigBee wireless sensor network. It also includes weather and climate data such as temperature, pressure, humidity, wind speed, visibility and dewpoint measured from Chievres airport. The data set is averaged for 10 minutes period and spanning 4.5 months.

Load the data¶

Load the numpy files X_train_AppliancesEnergy.npy, X_test_AppliancesEnergy.npy, y_train_AppliancesEnergy.npy, y_test_AppliancesEnergy.npy

In [ ]:
 

Data Understanding/Preparation¶

similar to the previous exercise, try to understand the data first!

In [ ]:
 

Regression¶

After you removed the main problems in the data, you can start the regression process. Similar to the previous exercise, you can use any regressor you saw in the course up to now. Find the best model in terms of MAE. As metric use neg_mean_absolute_error in the cross_val_score function (higher is better).

In [ ]:
from sklearn.model_selection import cross_val_score

Dummy Regressor¶

In [ ]:
from sktime.regression.dummy import DummyRegressor
In [ ]:
dummy = DummyRegressor()
In [ ]:
cross_val_score(dummy, X_train, y_train, cv=5, scoring="neg_mean_absolute_error").mean()

Evaluation¶

let's train the best model on the whole training set and evaluate it on the test set

In [ ]: