{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Linear Regression for Diabetes dataset - Lesson 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import needed libraries" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(442, 10)\n", "[ 0.03807591 0.05068012 0.06169621 0.02187239 -0.0442235 -0.03482076\n", " -0.04340085 -0.00259226 0.01990749 -0.01764613]\n" ] } ], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from sklearn import datasets, linear_model, model_selection\n", "\n", "# Load the diabetes dataset\n", "X, y= datasets.load_diabetes(return_X_y=True)\n", "# Print the shape of the data and the first row\n", "print(X.shape)\n", "print(X[0])" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(442,)\n", "(442, 1)\n" ] } ], "source": [ "# Extract the column at index 2 bmi\n", "X = X[:,2]\n", "print(X.shape)\n", "\n", "# Shape to a 2D array\n", "X = X.reshape(-1,1)\n", "print(X.shape)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "# split the data into training and testing data\n", "X_train, X_test,y_train, y_test = model_selection.train_test_split(X,y, test_size=0.33)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
LinearRegression()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
| \n", " | fit_intercept | \n", "True | \n", "
| \n", " | copy_X | \n", "True | \n", "
| \n", " | tol | \n", "1e-06 | \n", "
| \n", " | n_jobs | \n", "None | \n", "
| \n", " | positive | \n", "False | \n", "