{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "30b61190-61c1-4dd2-a9ec-acbadc8a52ef",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Supervised learning - Classification\n",
    "Goal of this excercise is to complete the hands-on experience task with similar task description as in the classification project case.\n",
    "\n",
    "We will use the modified Household Prices Dataset.\n",
    "\n",
    "Data source: https://www.kaggle.com/c/house-prices-advanced-regression-techniques/data\n",
    "\n",
    "Important attributes description:\n",
    "* SalePrice: The property's sale price in dollars. This is the target variable that you're trying to predict.\n",
    "* MSSubClass: The building class\n",
    "* BldgType: Type of dwelling\n",
    "* HouseStyle: Style of dwelling\n",
    "* OverallQual: Overall material and finish quality\n",
    "* OverallCond: Overall condition rating\n",
    "* YearBuilt: Original construction date\n",
    "* Heating: Type of heating\n",
    "* CentralAir: Central air conditioning\n",
    "* GrLivArea: Above grade (ground) living area square feet\n",
    "* BedroomAbvGr: Number of bedrooms above basement level)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "95c8f408-80d7-4082-9f14-a56c24c6a7da",
   "metadata": {},
   "source": [
    "### Complete the following tasks:\n",
    "1. **Describe what operations you are performing for each of the features**\n",
    "    - Mainly focus on categorical features\n",
    "2. Answer the following questions:\n",
    "    - **How many values are missing?**\n",
    "    - **How many instances do you have in each of the classes?**\n",
    "    - **Which metric score do you propose for the classification model performance evaluation?**\n",
    "        - Hint: This depends on your previous answer\n",
    "3. Finish your preprocessing pipeline and split the data into the Input and Output part (i.e. X and y variables)\n",
    "4. Start with the Decision tree model\n",
    "    - Use 5-fold cross validation\n",
    "    - **Will you use *standard* cross validation or *stratified* cross validation? Why?**\n",
    "    - Compute mean of the obtained score values\n",
    "5. Select one other algorithm from https://scikit-learn.org/stable/supervised_learning.html\n",
    "    - Repeat the 5-fold CV\n",
    "6. **Write down which model is better and why**\n",
    "7. Do **5 experiments** with hyper-parameters\n",
    "    - Set the parameters\n",
    "    - Do the 5-fold CV\n",
    "    - Note the settings and score in the Markdown cell\n",
    "8. **Write down  which model is the best and why**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a70c5553-ad01-4d43-93fb-50c085f09a64",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "import math\n",
    "\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.model_selection import train_test_split, StratifiedKFold, KFold\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "from sklearn.metrics import accuracy_score, f1_score, recall_score, precision_score, confusion_matrix, auc\n",
    "from sklearn.preprocessing import OrdinalEncoder\n",
    "from sklearn.neural_network import MLPClassifier"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91919c63-d578-4f60-ab66-6b319e4d8aee",
   "metadata": {},
   "source": [
    "## We will use categorized price as a target variable\n",
    "- Our goal is to predict if the house will be sold for more than 250k USD or not"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c04fdf9-7fbf-48ac-ba7a-a8c748b16703",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('zsu_cv1_data.csv').loc[:, ['SalePrice','MSSubClass','BldgType','HouseStyle','OverallQual','OverallCond','YearBuilt','Heating','CentralAir','GrLivArea','BedroomAbvGr']]\n",
    "df.loc[:, ['Target']] = (df.SalePrice > 250000).astype(int)\n",
    "df = df.drop(['SalePrice'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f24a55f9-b2c2-4815-a0b5-ceb261895856",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f284c232-b4e3-40fc-b502-a3f27c4b67ba",
   "metadata": {},
   "source": [
    "## Take a look at the features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c6ba193-7e2c-4e4b-9bf8-cf75e5689c36",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "015a2cf3-4dde-4722-97b9-0217e60cda00",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.describe(exclude=np.number)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3782fb16-bb52-461c-a415-5f13f22aa1f0",
   "metadata": {},
   "source": [
    "# Task (2p)\n",
    "- Finished the proposed tasks\n",
    "\n",
    "**Write down conclusion to the Markdown cell**"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
