{ "cells": [ { "cell_type": "markdown", "id": "latin-fiber", "metadata": {}, "source": [ "# A.I. Assignment 2" ] }, { "cell_type": "markdown", "id": "agreed-ferry", "metadata": {}, "source": [ "## Learning Goals\n", "\n", "By the end of this lab, you should be able to:\n", "* Perform some data preproscessing like: data scaling, normalisatin, encoding categorical features\n", "* Feel comfortable with simple linear regression\n", "* Feel comfortable with a regularization in ML\n", "\n", "\n", "### Content:\n", "\n", "The Lab. has 3 sections: \n", "\n", "1. Preprocessing\n", "2. Simple Linear regression\n", "3. Regularization\n", "\n", "At the end of each section there is an exercise, each worthing 3 points. All the work must be done during the lab and uploaded on teams by the end of the lab. \n", "\n", "\n", "If there are any python libraries missing, please install them on your working environment. " ] }, { "cell_type": "code", "execution_count": 1, "id": "independent-bench", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import scipy as sp\n", "import matplotlib as mpl\n", "import matplotlib.cm as cm\n", "import matplotlib.pyplot as plt\n", "import pandas as pd" ] }, { "cell_type": "markdown", "id": "brown-auditor", "metadata": {}, "source": [ "# Section 1. Preprocessing data\n", "\n", "### Standardization, or mean removal and variance scaling\n", "\n", "Standardization of datasets is a common requirement for many machine learning estimators; they might behave badly if the individual features do not more or less look like standard normally distributed data: Gaussian with zero mean and unit variance.\n", "\n", "\n", "In practice we often ignore the shape of the distribution and just transform the data to center it by removing the mean value of each feature, then scale it by dividing non-constant features by their standard deviation.\n", "\n", "\n", "For instance, many elements used in the objective function of a learning algorithm may assume that all features are centered around zero or have variance in the same order. If a feature has a variance that is orders of magnitude larger than others, it might dominate the objective function and make the estimator unable to learn from other features correctly as expected.\n", "\n", "The preprocessing module provides the StandardScaler utility class, which is a quick and easy way to perform the following operation on an array-like dataset:" ] }, { "cell_type": "code", "execution_count": 2, "id": "fabulous-washer", "metadata": {}, "outputs": [], "source": [ "from sklearn import preprocessing" ] }, { "cell_type": "code", "execution_count": 3, "id": "cathedral-china", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
StandardScaler()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
StandardScaler()
OrdinalEncoder()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
OrdinalEncoder()