{ "cells": [ { "cell_type": "markdown", "id": "9496e038", "metadata": {}, "source": [ "# Lineare Regression mit 1 Feature ($d=1$)" ] }, { "cell_type": "code", "execution_count": 1, "id": "5754d665", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "# plotting settings\n", "pd.plotting.register_matplotlib_converters()\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "import seaborn as sns" ] }, { "cell_type": "markdown", "id": "282549b7", "metadata": {}, "source": [ "Wir verwenden hier beispielhaft den Datensatz [Melbourne Housing Snapshot](https://www.kaggle.com/datasets/dansbecker/melbourne-housing-snapshot). Diesen finden Sie auch im Moodle unter `data/melb_data.csv`." ] }, { "cell_type": "code", "execution_count": 2, "id": "cfe20800", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['Suburb', 'Address', 'Rooms', 'Type', 'Price', 'Method', 'SellerG',\n", " 'Date', 'Distance', 'Postcode', 'Bedroom2', 'Bathroom', 'Car',\n", " 'Landsize', 'BuildingArea', 'YearBuilt', 'CouncilArea', 'Lattitude',\n", " 'Longtitude', 'Regionname', 'Propertycount'],\n", " dtype='object')" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "melbourne_file_path = 'data/melb_data.csv'\n", "melbourne_data = pd.read_csv(melbourne_file_path)\n", "melbourne_data = melbourne_data.dropna(axis=0) # entfernen von Daten mit fehlenden Werten\n", "melbourne_data.columns # Spaltennamen der Tabelle (potentielle Features)" ] }, { "cell_type": "code", "execution_count": 3, "id": "e13b23ac", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Suburb | \n", "Address | \n", "Rooms | \n", "Type | \n", "Price | \n", "Method | \n", "SellerG | \n", "Date | \n", "Distance | \n", "Postcode | \n", "... | \n", "Bathroom | \n", "Car | \n", "Landsize | \n", "BuildingArea | \n", "YearBuilt | \n", "CouncilArea | \n", "Lattitude | \n", "Longtitude | \n", "Regionname | \n", "Propertycount | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | \n", "Abbotsford | \n", "25 Bloomburg St | \n", "2 | \n", "h | \n", "1035000.0 | \n", "S | \n", "Biggin | \n", "4/02/2016 | \n", "2.5 | \n", "3067.0 | \n", "... | \n", "1.0 | \n", "0.0 | \n", "156.0 | \n", "79.0 | \n", "1900.0 | \n", "Yarra | \n", "-37.8079 | \n", "144.9934 | \n", "Northern Metropolitan | \n", "4019.0 | \n", "
2 | \n", "Abbotsford | \n", "5 Charles St | \n", "3 | \n", "h | \n", "1465000.0 | \n", "SP | \n", "Biggin | \n", "4/03/2017 | \n", "2.5 | \n", "3067.0 | \n", "... | \n", "2.0 | \n", "0.0 | \n", "134.0 | \n", "150.0 | \n", "1900.0 | \n", "Yarra | \n", "-37.8093 | \n", "144.9944 | \n", "Northern Metropolitan | \n", "4019.0 | \n", "
4 | \n", "Abbotsford | \n", "55a Park St | \n", "4 | \n", "h | \n", "1600000.0 | \n", "VB | \n", "Nelson | \n", "4/06/2016 | \n", "2.5 | \n", "3067.0 | \n", "... | \n", "1.0 | \n", "2.0 | \n", "120.0 | \n", "142.0 | \n", "2014.0 | \n", "Yarra | \n", "-37.8072 | \n", "144.9941 | \n", "Northern Metropolitan | \n", "4019.0 | \n", "
6 | \n", "Abbotsford | \n", "124 Yarra St | \n", "3 | \n", "h | \n", "1876000.0 | \n", "S | \n", "Nelson | \n", "7/05/2016 | \n", "2.5 | \n", "3067.0 | \n", "... | \n", "2.0 | \n", "0.0 | \n", "245.0 | \n", "210.0 | \n", "1910.0 | \n", "Yarra | \n", "-37.8024 | \n", "144.9993 | \n", "Northern Metropolitan | \n", "4019.0 | \n", "
7 | \n", "Abbotsford | \n", "98 Charles St | \n", "2 | \n", "h | \n", "1636000.0 | \n", "S | \n", "Nelson | \n", "8/10/2016 | \n", "2.5 | \n", "3067.0 | \n", "... | \n", "1.0 | \n", "2.0 | \n", "256.0 | \n", "107.0 | \n", "1890.0 | \n", "Yarra | \n", "-37.8060 | \n", "144.9954 | \n", "Northern Metropolitan | \n", "4019.0 | \n", "
5 rows × 21 columns
\n", "\n", " | BuildingArea | \n", "Price | \n", "
---|---|---|
1 | \n", "79.0 | \n", "1035000.0 | \n", "
2 | \n", "150.0 | \n", "1465000.0 | \n", "
4 | \n", "142.0 | \n", "1600000.0 | \n", "
6 | \n", "210.0 | \n", "1876000.0 | \n", "
7 | \n", "107.0 | \n", "1636000.0 | \n", "