{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"toc_visible":true,"collapsed_sections":["4zw1zRd6eJL7","T_QkeG6L3Kut","2tRxaHkXKipl"],"authorship_tag":"ABX9TyO9P8OiNQxQnajwUt9lPDN+"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["# PAL Machine Learning Workshop: Linear Regression\n","---\n","Hi all! Welcome to this workshop! Today we're going to do some really cool stuff with linear machine learning models.\n","\n","We will start by importing the necessary packages and data, then define our first linear model and try to optimize it for our task.\n","\n","Let's begin!"],"metadata":{"id":"WtrRno2HT3A7"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"k7CUZtQRTbno"},"outputs":[],"source":["# Linear algebra\n","import numpy as np\n","# Nice tool for data manipulation\n","import pandas as pd\n","# Visualizing our data\n","import matplotlib.pyplot as plt"]},{"cell_type":"markdown","source":["## Data Loading"],"metadata":{"id":"ZCGCQegmT_Pf"}},{"cell_type":"markdown","source":["We will start by downloading the diabetes dataset frm `sklearn`. This dataset contains ten baseline variables: age, sex, body mass index, average blood pressure, and six blood serum measurements, that were obtained from 442 diabetes patients."],"metadata":{"id":"h_cbTj5bUbN6"}},{"cell_type":"code","source":["from sklearn import datasets\n","\n","# Load the data\n","diabetes = datasets.load_diabetes(as_frame=True)\n","\n","# Get features and targets\n","diabetes_X, diabetes_y = diabetes.data, diabetes.target\n","diabetes_X.head()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":206},"id":"yRse2z7xUBNh","executionInfo":{"status":"ok","timestamp":1677159017931,"user_tz":0,"elapsed":10,"user":{"displayName":"Sergey Kuznetsov","userId":"02803571248049057958"}},"outputId":"f95b512f-62d8-420d-cbcf-21e831a4e630"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" age sex bmi bp s1 s2 s3 \\\n","0 0.038076 0.050680 0.061696 0.021872 -0.044223 -0.034821 -0.043401 \n","1 -0.001882 -0.044642 -0.051474 -0.026328 -0.008449 -0.019163 0.074412 \n","2 0.085299 0.050680 0.044451 -0.005671 -0.045599 -0.034194 -0.032356 \n","3 -0.089063 -0.044642 -0.011595 -0.036656 0.012191 0.024991 -0.036038 \n","4 0.005383 -0.044642 -0.036385 0.021872 0.003935 0.015596 0.008142 \n","\n"," s4 s5 s6 \n","0 -0.002592 0.019908 -0.017646 \n","1 -0.039493 -0.068330 -0.092204 \n","2 -0.002592 0.002864 -0.025930 \n","3 0.034309 0.022692 -0.009362 \n","4 -0.002592 -0.031991 -0.046641 "],"text/html":["\n","
\n"," | age | \n","sex | \n","bmi | \n","bp | \n","s1 | \n","s2 | \n","s3 | \n","s4 | \n","s5 | \n","s6 | \n","
---|---|---|---|---|---|---|---|---|---|---|
0 | \n","0.038076 | \n","0.050680 | \n","0.061696 | \n","0.021872 | \n","-0.044223 | \n","-0.034821 | \n","-0.043401 | \n","-0.002592 | \n","0.019908 | \n","-0.017646 | \n","
1 | \n","-0.001882 | \n","-0.044642 | \n","-0.051474 | \n","-0.026328 | \n","-0.008449 | \n","-0.019163 | \n","0.074412 | \n","-0.039493 | \n","-0.068330 | \n","-0.092204 | \n","
2 | \n","0.085299 | \n","0.050680 | \n","0.044451 | \n","-0.005671 | \n","-0.045599 | \n","-0.034194 | \n","-0.032356 | \n","-0.002592 | \n","0.002864 | \n","-0.025930 | \n","
3 | \n","-0.089063 | \n","-0.044642 | \n","-0.011595 | \n","-0.036656 | \n","0.012191 | \n","0.024991 | \n","-0.036038 | \n","0.034309 | \n","0.022692 | \n","-0.009362 | \n","
4 | \n","0.005383 | \n","-0.044642 | \n","-0.036385 | \n","0.021872 | \n","0.003935 | \n","0.015596 | \n","0.008142 | \n","-0.002592 | \n","-0.031991 | \n","-0.046641 | \n","