diff --git a/IML Projects/Task 1a/data/results.csv b/IML Projects/Task 1a/data/results.csv new file mode 100644 index 0000000..13ba238 --- /dev/null +++ b/IML Projects/Task 1a/data/results.csv @@ -0,0 +1,5 @@ +5.503638303110 +5.480400276223 +5.469885552772 +5.931931132834 +6.243346500145 diff --git a/IML Projects/Task 1a/data/sample.csv b/IML Projects/Task 1a/data/sample.csv new file mode 100644 index 0000000..ea8a566 --- /dev/null +++ b/IML Projects/Task 1a/data/sample.csv @@ -0,0 +1,5 @@ +13.145520802298 +9.601847478657 +6.087285844829 +14.511194012770 +22.066089946694 diff --git a/IML Projects/Task 1a/data/template_solution.ipynb b/IML Projects/Task 1a/data/template_solution.ipynb new file mode 100644 index 0000000..2a8be48 --- /dev/null +++ b/IML Projects/Task 1a/data/template_solution.ipynb @@ -0,0 +1,811 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### General guidance\n", + "\n", + "This serves as a template which will guide you through the implementation of this task. It is advised\n", + "to first read the whole template and get a sense of the overall structure of the code before trying to fill in any of the TODO gaps.\n", + "This is the jupyter notebook version of the template. For the python file version, please refer to the file `template_solution.py`.\n", + "\n", + "First, we import necessary libraries:" + ] + }, + { + "cell_type": "code", + "metadata": { + "ExecuteTime": { + "end_time": "2026-03-11T20:25:46.118936Z", + "start_time": "2026-03-11T20:25:46.115270Z" + } + }, + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "from sklearn.model_selection import KFold\n", + "\n", + "# Add any additional imports here (however, the task is solvable without using \n", + "# any additional imports)\n", + "# import ..." + ], + "outputs": [], + "execution_count": 55 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " #### Loading data" + ] + }, + { + "cell_type": "code", + "metadata": { + "ExecuteTime": { + "end_time": "2026-03-11T20:25:46.151114Z", + "start_time": "2026-03-11T20:25:46.143378Z" + } + }, + "source": [ + "data = pd.read_csv(\"train.csv\")\n", + "y = data[\"y\"].to_numpy()\n", + "data = data.drop(columns=\"y\")\n", + "# print a few data samples\n", + "print(data.head())" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 \\\n", + "0 0.06724 0.0 3.24 0.0 0.460 6.333 17.2 5.2146 4.0 430.0 16.9 \n", + "1 9.23230 0.0 18.10 0.0 0.631 6.216 100.0 1.1691 24.0 666.0 20.2 \n", + "2 0.11425 0.0 13.89 1.0 0.550 6.373 92.4 3.3633 5.0 276.0 16.4 \n", + "3 24.80170 0.0 18.10 0.0 0.693 5.349 96.0 1.7028 24.0 666.0 20.2 \n", + "4 0.05646 0.0 12.83 0.0 0.437 6.232 53.7 5.0141 5.0 398.0 18.7 \n", + "\n", + " x12 x13 \n", + "0 375.21 7.34 \n", + "1 366.15 9.53 \n", + "2 393.74 10.50 \n", + "3 396.90 19.77 \n", + "4 386.40 12.34 \n" + ] + } + ], + "execution_count": 56 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Calculating the average RMSE" + ] + }, + { + "cell_type": "code", + "metadata": { + "ExecuteTime": { + "end_time": "2026-03-11T20:25:46.175778Z", + "start_time": "2026-03-11T20:25:46.173181Z" + } + }, + "source": [ + "def calculate_RMSE(w, X, y):\n", + " \"\"\"This function takes test data points (X and y), and computes the empirical RMSE of \n", + " predicting y from X using a linear model with weights w. \n", + "\n", + " Parameters\n", + " ----------\n", + " w: array of floats: dim = (13,), optimal parameters of ridge regression \n", + " X: matrix of floats, dim = (15,13), inputs with 13 features\n", + " y: array of floats, dim = (15,), input labels\n", + "\n", + " Returns\n", + " ----------\n", + " rmse: float: dim = 1, RMSE value\n", + " \"\"\"\n", + " rmse = 0\n", + " n = X.shape[0]\n", + " rmse = np.sqrt(1/n * np.sum( (y - X @ w)**2 ))\n", + " assert np.isscalar(rmse)\n", + " return rmse" + ], + "outputs": [], + "execution_count": 57 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Fitting the regressor" + ] + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "The fitting can be carried out by solving the normal equations:\n", + "$$\n", + "(\\lambda \\cdot \\mathbf{I} + \\mathbf{X}) \\mathbf{w} = \\mathbf{X}^{T}\\cdot \\mathbf{y}\n", + "$$\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "ExecuteTime": { + "end_time": "2026-03-11T20:25:46.200893Z", + "start_time": "2026-03-11T20:25:46.197877Z" + } + }, + "source": [ + "def fit(X, y, lam):\n", + " \"\"\"\n", + " This function receives training data points, then fits the ridge regression on this data\n", + " with regularization hyperparameter lambda. The weights w of the fitted ridge regression\n", + " are returned. \n", + "\n", + " Parameters\n", + " ----------\n", + " X: matrix of floats, dim = (135,13), inputs with 13 features\n", + " y: array of floats, dim = (135,), input labels\n", + " lam: float. lambda parameter, used in regularization term\n", + "\n", + " Returns\n", + " ----------\n", + " w: array of floats: dim = (13,), optimal parameters of ridge regression\n", + " \"\"\"\n", + " weights = np.zeros((13,))\n", + " A = lam * np.identity(13) + np.transpose(X) @ X\n", + " b = X.T @ y\n", + " weights = np.linalg.solve(A, b)\n", + "\n", + " assert weights.shape == (13,)\n", + " return weights" + ], + "outputs": [], + "execution_count": 58 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Performing computation" + ] + }, + { + "cell_type": "code", + "metadata": { + "ExecuteTime": { + "end_time": "2026-03-11T20:27:41.325447Z", + "start_time": "2026-03-11T20:27:41.305479Z" + } + }, + "source": [ + "\"\"\"\n", + "Main cross-validation loop, implementing 10-fold CV. In every iteration \n", + "(for every train-test split), the RMSE for every lambda is calculated, \n", + "and then averaged over iterations.\n", + "\n", + "Parameters\n", + "---------- \n", + "X: matrix of floats, dim = (150, 13), inputs with 13 features\n", + "y: array of floats, dim = (150, ), input labels\n", + "lambdas: list of floats, len = 5, values of lambda for which ridge regression is fitted and RMSE estimated\n", + "n_folds: int, number of folds (pieces in which we split the dataset), parameter K in KFold CV\n", + "\n", + "Compute\n", + "----------\n", + "avg_RMSE: array of floats: dim = (5,), average RMSE value for every lambda\n", + "\"\"\"\n", + "X = data.to_numpy()\n", + "# The function calculating the average RMSE\n", + "lambdas = [0.1, 1, 10, 100, 200]\n", + "n_folds = 10\n", + "\n", + "RMSE_mat = np.zeros((n_folds, len(lambdas)))\n", + "\n", + "\n", + "# and fill all entries in the matrix 'RMSE_mat'\n", + "for k in range(n_folds):\n", + " fold = 150 // n_folds\n", + " X_train = np.concatenate((X[:k*fold,:], X[(k+1)*fold:,:]),axis=0) # leave out the validation set\n", + " X_validation = X[k*fold:(k+1)*fold,:]\n", + " y_train = np.concatenate((y[:k*fold], y[(k+1)*fold:]))\n", + " y_validation = y[k*fold:(k+1)*fold]\n", + " for i in range(len(lambdas)):\n", + " w = fit(X_train, y_train, lambdas[i])\n", + " RMSE_mat[k,i] = calculate_RMSE(w, X_validation, y_validation)\n", + "avg_RMSE = np.mean(RMSE_mat, axis=0) # avg_RMSE: array of floats: dim = (5,), average RMSE value for every lambda\n", + "assert avg_RMSE.shape == (5,)" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[7.4412339 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 0. ]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 7.99355906]\n", + " [0. 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 7.99355906]\n", + " [4.88759828 0. 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 7.99355906]\n", + " [4.88759828 4.88177704 0. 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 7.99355906]\n", + " [4.88759828 4.88177704 4.70584949 0. 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 7.99355906]\n", + " [4.88759828 4.88177704 4.70584949 4.30299719 0. ]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 7.99355906]\n", + " [4.88759828 4.88177704 4.70584949 4.30299719 4.45025962]\n", + " [0. 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 7.99355906]\n", + " [4.88759828 4.88177704 4.70584949 4.30299719 4.45025962]\n", + " [3.5549224 0. 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 7.99355906]\n", + " [4.88759828 4.88177704 4.70584949 4.30299719 4.45025962]\n", + " [3.5549224 3.47254925 0. 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 7.99355906]\n", + " [4.88759828 4.88177704 4.70584949 4.30299719 4.45025962]\n", + " [3.5549224 3.47254925 3.38243796 0. 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 7.99355906]\n", + " [4.88759828 4.88177704 4.70584949 4.30299719 4.45025962]\n", + " [3.5549224 3.47254925 3.38243796 3.79878164 0. ]]\n", + "[[7.4412339 7.47793331 7.58146902 8.19645872 8.50748161]\n", + " [5.12826602 4.88393133 4.45282503 3.55256057 3.60399295]\n", + " [7.70764701 7.70279186 7.72774439 7.77994411 7.88968326]\n", + " [4.54006065 4.50059526 4.33989198 4.94678494 5.24054741]\n", + " [4.07531646 4.0726219 4.19425423 4.89426434 5.24272243]\n", + " [5.10975443 5.15192098 5.39446252 7.11982551 7.87880031]\n", + " [6.55136404 6.56151161 6.55275056 7.13545034 7.47865912]\n", + " [6.04021985 6.09837022 6.36717035 7.59224397 7.99355906]\n", + " [4.88759828 4.88177704 4.70584949 4.30299719 4.45025962]\n", + " [3.5549224 3.47254925 3.38243796 3.79878164 4.14775924]]\n" + ] + } + ], + "execution_count": 64 + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2026-03-11T20:25:46.251095Z", + "start_time": "2026-03-11T20:25:46.248154Z" + } + }, + "cell_type": "code", + "source": [ + "A = np.array([[1,2],[3,4]])\n", + "#print(A[:,:1])\n", + "#print(np.transpose(A), A, np.transpose(A) @ A)\n", + "print(np.concatenate((A,A),axis=1))" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1 2 1 2]\n", + " [3 4 3 4]]\n" + ] + } + ], + "execution_count": 60 + }, + { + "cell_type": "code", + "metadata": { + "ExecuteTime": { + "end_time": "2026-03-11T20:25:46.295067Z", + "start_time": "2026-03-11T20:25:46.292066Z" + } + }, + "source": [ + "# Save results in the required format\n", + "np.savetxt(\"./results.csv\", avg_RMSE, fmt=\"%.12f\")" + ], + "outputs": [], + "execution_count": 61 + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2026-03-11T20:25:46.321558Z", + "start_time": "2026-03-11T20:25:46.319798Z" + } + }, + "cell_type": "code", + "source": "# Validate", + "outputs": [], + "execution_count": 62 + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/IML Projects/Task 1a/data/template_solution.py b/IML Projects/Task 1a/data/template_solution.py new file mode 100644 index 0000000..a22eb6d --- /dev/null +++ b/IML Projects/Task 1a/data/template_solution.py @@ -0,0 +1,95 @@ +# This serves as a template which will guide you through the implementation of this task. It is advised +# to first read the whole template and get a sense of the overall structure of the code before trying to fill in any of the TODO gaps. +# First, we import necessary libraries: +import pandas as pd +import numpy as np +from sklearn.model_selection import KFold + +# Add any additional imports here (however, the task is solvable without using +# any additional imports) +# import ... + +def fit(X, y, lam): + """ + This function receives training data points, then fits the ridge regression on this data + with regularization hyperparameter lambda. The weights w of the fitted ridge regression + are returned. + + Parameters + ---------- + X: matrix of floats, dim = (135,13), inputs with 13 features + y: array of floats, dim = (135,), input labels + lam: float. lambda parameter, used in regularization term + + Returns + ---------- + w: array of floats: dim = (13,), optimal parameters of ridge regression + """ + weights = np.zeros((13,)) + # TODO: Enter your code here + assert weights.shape == (13,) + return weights + + +def calculate_RMSE(w, X, y): + """This function takes test data points (X and y), and computes the empirical RMSE of + predicting y from X using a linear model with weights w. + + Parameters + ---------- + w: array of floats: dim = (13,), optimal parameters of ridge regression + X: matrix of floats, dim = (15,13), inputs with 13 features + y: array of floats, dim = (15,), input labels + + Returns + ---------- + rmse: float: dim = 1, RMSE value + """ + rmse = 0 + # TODO: Enter your code here + assert np.isscalar(rmse) + return rmse + + +def average_LR_RMSE(X, y, lambdas, n_folds): + """ + Main cross-validation loop, implementing 10-fold CV. In every iteration (for every train-test split), the RMSE for every lambda is calculated, + and then averaged over iterations. + + Parameters + ---------- + X: matrix of floats, dim = (150, 13), inputs with 13 features + y: array of floats, dim = (150, ), input labels + lambdas: list of floats, len = 5, values of lambda for which ridge regression is fitted and RMSE estimated + n_folds: int, number of folds (pieces in which we split the dataset), parameter K in KFold CV + + Returns + ---------- + avg_RMSE: array of floats: dim = (5,), average RMSE value for every lambda + """ + RMSE_mat = np.zeros((n_folds, len(lambdas))) + + # TODO: Enter your code here. Hint: Use functions 'fit' and 'calculate_RMSE' with training and test data + # and fill all entries in the matrix 'RMSE_mat' + + avg_RMSE = np.mean(RMSE_mat, axis=0) + assert avg_RMSE.shape == (5,) + return avg_RMSE + + +# Main function. You don't have to change this +if __name__ == "__main__": + # Data loading + data = pd.read_csv("train.csv") + y = data["y"].to_numpy() + data = data.drop(columns="y") + # print a few data samples + print(data.head()) + + X = data.to_numpy() + # The function calculating the average RMSE + lambdas = [0.1, 1, 10, 100, 200] + n_folds = 10 + avg_RMSE = average_LR_RMSE(X, y, lambdas, n_folds) + # Save results in the required format + np.savetxt("./results.csv", avg_RMSE, fmt="%.12f") diff --git a/IML Projects/Task 1a/data/train.csv b/IML Projects/Task 1a/data/train.csv new file mode 100644 index 0000000..fd96c42 --- /dev/null +++ b/IML Projects/Task 1a/data/train.csv @@ -0,0 +1,151 @@ +y,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13 +22.6,0.06724,0.0,3.24,0.0,0.46,6.333,17.2,5.2146,4.0,430.0,16.9,375.21,7.34 +50.0,9.2323,0.0,18.1,0.0,0.631,6.216,100.0,1.1691,24.0,666.0,20.2,366.15,9.53 +23.0,0.11425,0.0,13.89,1.0,0.55,6.373,92.4,3.3633,5.0,276.0,16.4,393.74,10.5 +8.3,24.8017,0.0,18.1,0.0,0.693,5.349,96.0,1.7028,24.0,666.0,20.2,396.9,19.77 +21.2,0.05646,0.0,12.83,0.0,0.437,6.232,53.7,5.0141,5.0,398.0,18.7,386.4,12.34 +19.9,0.62739,0.0,8.14,0.0,0.538,5.834,56.5,4.4986,4.0,307.0,21.0,395.62,8.47 +20.6,4.83567,0.0,18.1,0.0,0.583,5.905,53.2,3.1523,24.0,666.0,20.2,388.22,11.45 +18.7,0.06151,0.0,5.19,0.0,0.515,5.968,58.5,4.8122,5.0,224.0,20.2,396.9,9.29 +16.1,2.63548,0.0,9.9,0.0,0.544,4.973,37.8,2.5194,4.0,304.0,18.4,350.45,12.64 +18.6,0.22876,0.0,8.56,0.0,0.52,6.405,85.4,2.7147,5.0,384.0,20.9,70.8,10.63 +8.8,73.5341,0.0,18.1,0.0,0.679,5.957,100.0,1.8026,24.0,666.0,20.2,16.45,20.62 +17.2,14.0507,0.0,18.1,0.0,0.597,6.657,100.0,1.5275,24.0,666.0,20.2,35.05,21.22 +14.9,6.28807,0.0,18.1,0.0,0.74,6.341,96.4,2.072,24.0,666.0,20.2,318.01,17.79 +10.5,24.3938,0.0,18.1,0.0,0.7,4.652,100.0,1.4672,24.0,666.0,20.2,396.9,28.28 +50.0,1.83377,0.0,19.58,1.0,0.605,7.802,98.2,2.0407,5.0,403.0,14.7,389.61,1.92 +29.0,0.05561,70.0,2.24,0.0,0.4,7.041,10.0,7.8278,5.0,358.0,14.8,371.58,4.74 +23.0,5.82401,0.0,18.1,0.0,0.532,6.242,64.7,3.4242,24.0,666.0,20.2,396.9,10.74 +33.3,0.04011,80.0,1.52,0.0,0.404,7.287,34.1,7.309,2.0,329.0,12.6,396.9,4.08 +29.4,0.06664,0.0,4.05,0.0,0.51,6.546,33.1,3.1323,5.0,296.0,16.6,390.96,5.33 +21.0,0.08014,0.0,5.96,0.0,0.499,5.85,41.5,3.9342,5.0,279.0,19.2,396.9,8.77 +23.8,0.1676,0.0,7.38,0.0,0.493,6.426,52.3,4.5404,5.0,287.0,19.6,396.9,7.2 +19.1,2.3139,0.0,19.58,0.0,0.605,5.88,97.3,2.3887,5.0,403.0,14.7,348.13,12.03 +20.4,0.13117,0.0,8.56,0.0,0.52,6.127,85.2,2.1224,5.0,384.0,20.9,387.69,14.09 +29.1,0.07978,40.0,6.41,0.0,0.447,6.482,32.1,4.1403,4.0,254.0,17.6,396.9,7.19 +19.3,0.17142,0.0,6.91,0.0,0.448,5.682,33.8,5.1004,3.0,233.0,17.9,396.9,10.21 +23.1,13.5222,0.0,18.1,0.0,0.631,3.863,100.0,1.5106,24.0,666.0,20.2,131.42,13.33 +19.6,0.85204,0.0,8.14,0.0,0.538,5.965,89.2,4.0123,4.0,307.0,21.0,392.53,13.83 +19.4,2.14918,0.0,19.58,0.0,0.871,5.709,98.5,1.6232,5.0,403.0,14.7,261.95,15.79 +38.7,0.12083,0.0,2.89,0.0,0.445,8.069,76.0,3.4952,2.0,276.0,18.0,396.9,4.21 +18.7,0.22212,0.0,10.01,0.0,0.547,6.092,95.4,2.548,6.0,432.0,17.8,396.9,17.09 +14.6,10.233,0.0,18.1,0.0,0.614,6.185,96.7,2.1705,24.0,666.0,20.2,379.7,18.03 +20.0,6.80117,0.0,18.1,0.0,0.713,6.081,84.4,2.7175,24.0,666.0,20.2,396.9,14.7 +20.5,0.19657,22.0,5.86,0.0,0.431,6.226,79.2,8.0555,7.0,330.0,19.1,376.14,10.15 +20.1,0.10612,30.0,4.93,0.0,0.428,6.095,65.1,6.3361,6.0,300.0,16.6,394.62,12.4 +23.6,0.09178,0.0,4.05,0.0,0.51,6.416,84.1,2.6463,5.0,296.0,16.6,395.5,9.04 +16.8,4.22239,0.0,18.1,1.0,0.77,5.803,89.0,1.9047,24.0,666.0,20.2,353.04,14.64 +5.6,25.0461,0.0,18.1,0.0,0.693,5.987,100.0,1.5888,24.0,666.0,20.2,396.9,26.77 +50.0,8.26725,0.0,18.1,1.0,0.668,5.875,89.6,1.1296,24.0,666.0,20.2,347.88,8.88 +14.5,8.49213,0.0,18.1,0.0,0.584,6.348,86.1,2.0527,24.0,666.0,20.2,83.45,17.64 +13.3,6.39312,0.0,18.1,0.0,0.584,6.162,97.4,2.206,24.0,666.0,20.2,302.76,24.1 +23.9,0.08265,0.0,13.92,0.0,0.437,6.127,18.4,5.5027,4.0,289.0,16.0,396.9,8.58 +20.0,0.18836,0.0,6.91,0.0,0.448,5.786,33.3,5.1004,3.0,233.0,17.9,396.9,14.15 +19.8,0.04544,0.0,3.24,0.0,0.46,6.144,32.2,5.8736,4.0,430.0,16.9,368.57,9.09 +13.8,8.05579,0.0,18.1,0.0,0.584,5.427,95.4,2.4298,24.0,666.0,20.2,352.58,18.14 +16.5,0.02498,0.0,1.89,0.0,0.518,6.54,59.7,6.2669,1.0,422.0,15.9,389.96,8.65 +21.6,0.02731,0.0,7.07,0.0,0.469,6.421,78.9,4.9671,2.0,242.0,17.8,396.9,9.14 +20.3,0.14103,0.0,13.92,0.0,0.437,5.79,58.0,6.32,4.0,289.0,16.0,396.9,15.84 +17.0,1.41385,0.0,19.58,1.0,0.871,6.129,96.0,1.7494,5.0,403.0,14.7,321.02,15.12 +11.8,2.77974,0.0,19.58,0.0,0.871,4.903,97.8,1.3459,5.0,403.0,14.7,396.9,29.29 +27.5,0.14866,0.0,8.56,0.0,0.52,6.727,79.9,2.7778,5.0,384.0,20.9,394.76,9.42 +15.6,3.53501,0.0,19.58,1.0,0.871,6.152,82.6,1.7455,5.0,403.0,14.7,88.01,15.02 +23.1,0.17899,0.0,9.69,0.0,0.585,5.67,28.8,2.7986,6.0,391.0,19.2,393.29,17.6 +24.3,0.537,0.0,6.2,0.0,0.504,5.981,68.1,3.6715,8.0,307.0,17.4,378.35,11.65 +42.8,0.36894,22.0,5.86,0.0,0.431,8.259,8.4,8.9067,7.0,330.0,19.1,396.9,3.54 +15.6,0.97617,0.0,21.89,0.0,0.624,5.757,98.4,2.346,4.0,437.0,21.2,262.76,17.31 +21.7,0.09378,12.5,7.87,0.0,0.524,5.889,39.0,5.4509,5.0,311.0,15.2,390.5,15.71 +17.1,0.05023,35.0,6.06,0.0,0.4379,5.706,28.4,6.6407,1.0,304.0,16.9,394.02,12.43 +17.2,0.06162,0.0,4.39,0.0,0.442,5.898,52.3,8.0136,3.0,352.0,18.8,364.61,12.67 +15.0,51.1358,0.0,18.1,0.0,0.597,5.757,100.0,1.413,24.0,666.0,20.2,2.6,10.11 +21.7,0.17446,0.0,10.59,1.0,0.489,5.96,92.1,3.8771,4.0,277.0,18.6,393.25,17.27 +18.6,0.07244,60.0,1.69,0.0,0.411,5.884,18.5,10.7103,4.0,411.0,18.3,392.33,7.79 +21.0,0.47547,0.0,9.9,0.0,0.544,6.113,58.8,4.0019,4.0,304.0,18.4,396.23,12.73 +33.1,0.1,34.0,6.09,0.0,0.433,6.982,17.7,5.4917,7.0,329.0,16.1,390.43,4.86 +31.5,0.44178,0.0,6.2,0.0,0.504,6.552,21.4,3.3751,8.0,307.0,17.4,380.34,3.76 +20.1,13.0751,0.0,18.1,0.0,0.58,5.713,56.7,2.8237,24.0,666.0,20.2,396.9,14.76 +29.8,0.12579,45.0,3.44,0.0,0.437,6.556,29.1,4.5667,5.0,398.0,15.2,382.84,4.56 +15.2,5.44114,0.0,18.1,0.0,0.713,6.655,98.2,2.3552,24.0,666.0,20.2,355.29,17.73 +15.0,0.22489,12.5,7.87,0.0,0.524,6.377,94.3,6.3467,5.0,311.0,15.2,392.52,20.45 +27.5,14.4383,0.0,18.1,0.0,0.597,6.852,100.0,1.4655,24.0,666.0,20.2,179.36,19.78 +22.6,0.13642,0.0,10.59,0.0,0.489,5.891,22.3,3.9454,4.0,277.0,18.6,396.9,10.87 +20.0,0.10153,0.0,12.83,0.0,0.437,6.279,74.5,4.0522,5.0,398.0,18.7,373.66,11.97 +21.4,0.09512,0.0,12.83,0.0,0.437,6.286,45.0,4.5026,5.0,398.0,18.7,383.23,8.94 +23.5,0.03584,80.0,3.37,0.0,0.398,6.29,17.8,6.6115,4.0,337.0,16.1,396.9,4.67 +31.2,0.03049,55.0,3.78,0.0,0.484,6.874,28.1,6.4654,5.0,370.0,17.6,387.97,4.61 +23.7,5.70818,0.0,18.1,0.0,0.532,6.75,74.9,3.3317,24.0,666.0,20.2,393.07,7.74 +7.4,22.5971,0.0,18.1,0.0,0.7,5.0,89.5,1.5184,24.0,666.0,20.2,396.9,31.99 +48.3,0.33147,0.0,6.2,0.0,0.507,8.247,70.4,3.6519,8.0,307.0,17.4,378.95,3.95 +24.4,0.22969,0.0,10.59,0.0,0.489,6.326,52.5,4.3549,4.0,277.0,18.6,394.87,10.97 +22.6,0.04684,0.0,3.41,0.0,0.489,6.417,66.1,3.0923,2.0,270.0,17.8,392.18,8.81 +18.3,0.26838,0.0,9.69,0.0,0.585,5.794,70.6,2.8927,6.0,391.0,19.2,396.9,14.1 +23.3,0.09252,30.0,4.93,0.0,0.428,6.606,42.2,6.1899,6.0,300.0,16.6,383.78,7.37 +17.1,0.35233,0.0,21.89,0.0,0.624,6.454,98.4,1.8498,4.0,437.0,21.2,394.08,14.59 +27.9,11.9511,0.0,18.1,0.0,0.659,5.608,100.0,1.2852,24.0,666.0,20.2,332.09,12.13 +44.8,0.31533,0.0,6.2,0.0,0.504,8.266,78.3,2.8944,8.0,307.0,17.4,385.05,4.14 +50.0,0.52693,0.0,6.2,0.0,0.504,8.725,83.0,2.8944,8.0,307.0,17.4,382.0,4.63 +23.0,0.30347,0.0,7.38,0.0,0.493,6.312,28.9,5.4159,5.0,287.0,19.6,396.9,6.15 +21.4,0.11504,0.0,2.89,0.0,0.445,6.163,69.6,3.4952,2.0,276.0,18.0,391.83,11.34 +10.2,12.2472,0.0,18.1,0.0,0.584,5.837,59.7,1.9976,24.0,666.0,20.2,24.65,15.69 +23.3,1.42502,0.0,19.58,0.0,0.871,6.51,100.0,1.7659,5.0,403.0,14.7,364.31,7.39 +23.2,5.29305,0.0,18.1,0.0,0.7,6.051,82.5,2.1678,24.0,666.0,20.2,378.38,18.76 +18.9,0.0136,75.0,4.0,0.0,0.41,5.888,47.6,7.3197,3.0,469.0,21.1,396.9,14.8 +13.4,11.1604,0.0,18.1,0.0,0.74,6.629,94.6,2.1247,24.0,666.0,20.2,109.85,23.27 +21.9,0.04819,80.0,3.64,0.0,0.392,6.108,32.0,9.2203,1.0,315.0,16.4,392.89,6.57 +24.8,0.04417,70.0,2.24,0.0,0.4,6.871,47.4,7.8278,5.0,358.0,14.8,390.86,6.07 +11.9,0.04741,0.0,11.93,0.0,0.573,6.03,80.8,2.505,1.0,273.0,21.0,396.9,7.88 +24.3,0.33983,22.0,5.86,0.0,0.431,6.108,34.9,8.0555,7.0,330.0,19.1,390.18,9.16 +13.8,18.4982,0.0,18.1,0.0,0.668,4.138,100.0,1.137,24.0,666.0,20.2,396.9,37.97 +24.7,0.02055,85.0,0.74,0.0,0.41,6.383,35.7,9.1876,2.0,313.0,17.3,396.9,5.77 +14.1,4.75237,0.0,18.1,0.0,0.713,6.525,86.5,2.4358,24.0,666.0,20.2,50.92,18.13 +18.7,0.14932,25.0,5.13,0.0,0.453,5.741,66.2,7.2254,8.0,284.0,19.7,395.11,13.15 +28.1,0.14052,0.0,10.59,0.0,0.489,6.375,32.3,3.9454,4.0,277.0,18.6,385.81,9.38 +19.8,0.12802,0.0,8.56,0.0,0.52,6.474,97.1,2.4329,5.0,384.0,20.9,395.24,12.27 +26.7,0.35809,0.0,6.2,1.0,0.507,6.951,88.5,2.8617,8.0,307.0,17.4,391.7,9.71 +21.7,0.15876,0.0,10.81,0.0,0.413,5.961,17.5,5.2873,4.0,305.0,19.2,376.94,9.88 +22.0,0.11329,30.0,4.93,0.0,0.428,6.897,54.3,6.3361,6.0,300.0,16.6,391.25,11.38 +22.9,0.08829,12.5,7.87,0.0,0.524,6.012,66.6,5.5605,5.0,311.0,15.2,395.6,12.43 +10.4,25.9406,0.0,18.1,0.0,0.679,5.304,89.1,1.6475,24.0,666.0,20.2,127.36,26.64 +21.9,3.69695,0.0,18.1,0.0,0.718,4.963,91.4,1.7523,24.0,666.0,20.2,316.03,14.0 +20.6,0.04527,0.0,11.93,0.0,0.573,6.12,76.7,2.2875,1.0,273.0,21.0,396.9,9.08 +26.4,0.09266,34.0,6.09,0.0,0.433,6.495,18.4,5.4917,7.0,329.0,16.1,383.61,8.67 +41.3,1.22358,0.0,19.58,0.0,0.605,6.943,97.4,1.8773,5.0,403.0,14.7,363.43,4.59 +17.2,7.40389,0.0,18.1,0.0,0.597,5.617,97.9,1.4547,24.0,666.0,20.2,314.64,26.4 +27.1,0.14455,12.5,7.87,0.0,0.524,6.172,96.1,5.9505,5.0,311.0,15.2,396.9,19.15 +20.4,0.13058,0.0,10.01,0.0,0.547,5.872,73.1,2.4775,6.0,432.0,17.8,338.63,15.37 +16.5,0.21124,12.5,7.87,0.0,0.524,5.631,100.0,6.0821,5.0,311.0,15.2,386.63,29.93 +24.4,0.13587,0.0,10.59,1.0,0.489,6.064,59.1,4.2392,4.0,277.0,18.6,381.32,14.66 +8.4,13.6781,0.0,18.1,0.0,0.74,5.935,87.9,1.8206,24.0,666.0,20.2,68.95,34.02 +23.0,0.59005,0.0,21.89,0.0,0.624,6.372,97.9,2.3274,4.0,437.0,21.2,385.76,11.12 +9.7,11.5779,0.0,18.1,0.0,0.7,5.036,97.0,1.77,24.0,666.0,20.2,396.9,25.68 +50.0,0.01501,90.0,1.21,1.0,0.401,7.923,24.8,5.885,1.0,198.0,13.6,395.52,3.16 +30.5,0.06911,45.0,3.44,0.0,0.437,6.739,30.8,6.4798,5.0,398.0,15.2,389.71,4.69 +12.3,7.99248,0.0,18.1,0.0,0.7,5.52,100.0,1.5331,24.0,666.0,20.2,396.9,24.56 +19.4,0.21977,0.0,6.91,0.0,0.448,5.602,62.0,6.0877,3.0,233.0,17.9,396.9,16.2 +21.2,0.23912,0.0,9.69,0.0,0.585,6.019,65.3,2.4091,6.0,391.0,19.2,396.9,12.92 +20.3,0.3494,0.0,9.9,0.0,0.544,5.972,76.7,3.1025,4.0,304.0,18.4,396.24,9.97 +18.8,0.09849,0.0,25.65,0.0,0.581,5.879,95.8,2.0063,2.0,188.0,19.1,379.38,17.58 +33.4,0.07503,33.0,2.18,0.0,0.472,7.42,71.9,3.0992,7.0,222.0,18.4,396.9,6.47 +18.5,0.19133,22.0,5.86,0.0,0.431,5.605,70.2,7.9549,7.0,330.0,19.1,389.13,18.46 +19.6,0.10328,25.0,5.13,0.0,0.453,5.927,47.2,6.932,8.0,284.0,19.7,396.9,9.22 +33.2,0.10469,40.0,6.41,1.0,0.447,7.267,49.0,4.7872,4.0,254.0,17.6,389.25,6.05 +13.1,8.71675,0.0,18.1,0.0,0.693,6.471,98.8,1.7257,24.0,666.0,20.2,391.98,17.12 +7.5,10.8342,0.0,18.1,0.0,0.679,6.782,90.8,1.8195,24.0,666.0,20.2,21.57,25.79 +13.6,0.10574,0.0,27.74,0.0,0.609,5.983,98.8,1.8681,4.0,711.0,20.1,390.11,18.07 +17.4,1.20742,0.0,19.58,0.0,0.605,5.875,94.6,2.4259,5.0,403.0,14.7,292.29,14.43 +8.4,11.8123,0.0,18.1,0.0,0.718,6.824,76.5,1.794,24.0,666.0,20.2,48.45,22.74 +35.4,0.01311,90.0,1.22,0.0,0.403,7.249,21.9,8.6966,5.0,226.0,17.9,395.93,4.81 +24.0,0.33045,0.0,6.2,0.0,0.507,6.086,61.5,3.6519,8.0,307.0,17.4,376.75,10.88 +13.4,3.32105,0.0,19.58,1.0,0.871,5.403,100.0,1.3216,5.0,403.0,14.7,396.9,26.82 +26.2,0.19073,22.0,5.86,0.0,0.431,6.718,17.5,7.8265,7.0,330.0,19.1,393.74,6.56 +7.2,18.0846,0.0,18.1,0.0,0.679,6.434,100.0,1.8347,24.0,666.0,20.2,27.25,29.05 +13.1,23.6482,0.0,18.1,0.0,0.671,6.38,96.2,1.3861,24.0,666.0,20.2,396.9,23.69 +24.5,0.27957,0.0,9.69,0.0,0.585,5.926,42.6,2.3817,6.0,391.0,19.2,396.9,13.59 +37.2,0.0578,0.0,2.46,0.0,0.488,6.98,58.4,2.829,3.0,193.0,17.8,396.9,5.04 +25.0,0.0536,21.0,5.64,0.0,0.439,6.511,21.1,6.8147,4.0,243.0,16.8,396.9,5.28 +24.1,0.07896,0.0,12.83,0.0,0.437,6.273,6.0,4.2515,5.0,398.0,18.7,394.92,6.78 +16.6,0.67191,0.0,8.14,0.0,0.538,5.813,90.3,4.682,4.0,307.0,21.0,376.88,14.81 +32.9,0.01778,95.0,1.47,0.0,0.403,7.135,13.9,7.6534,3.0,402.0,17.0,384.3,4.45 +36.2,0.06905,0.0,2.18,0.0,0.458,7.147,54.2,6.0622,3.0,222.0,18.7,396.9,5.33 +11.0,7.36711,0.0,18.1,0.0,0.679,6.193,78.1,1.9356,24.0,666.0,20.2,96.73,21.52 +7.2,16.8118,0.0,18.1,0.0,0.7,5.277,98.1,1.4261,24.0,666.0,20.2,396.9,30.81 diff --git a/IML Projects/Task 1a/task_description_1a.pdf b/IML Projects/Task 1a/task_description_1a.pdf new file mode 100644 index 0000000..385c8f9 Binary files /dev/null and b/IML Projects/Task 1a/task_description_1a.pdf differ