{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 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.005670 -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 Target \n", "0 -0.002592 0.019907 -0.017646 1 \n", "1 -0.039493 -0.068332 -0.092204 0 \n", "2 -0.002592 0.002861 -0.025930 1 \n", "3 0.034309 0.022688 -0.009362 1 \n", "4 -0.002592 -0.031988 -0.046641 0 \n" ] } ], "source": [ "from sklearn.datasets import load_diabetes\n", "import pandas as pd\n", "import numpy as np\n", "\n", "# Load the diabetes dataset\n", "diabetes = load_diabetes()\n", "X = diabetes.data\n", "y = diabetes.target\n", "\n", "# Convert the target into a binary classification problem by thresholding at the median\n", "threshold = np.median(y)\n", "y_binary = (y > threshold).astype(int)\n", "\n", "# Display the first few rows of the data\n", "df = pd.DataFrame(X, columns=diabetes.feature_names)\n", "df['Target'] = y_binary\n", "print(df.head())\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "X_train shape: (353, 10)\n", "X_test shape: (89, 10)\n" ] } ], "source": [ "from sklearn.model_selection import train_test_split\n", "from sklearn.preprocessing import StandardScaler\n", "\n", "# Split the data into training and test sets (80% train, 20% test)\n", "X_train, X_test, y_train, y_test = train_test_split(X, y_binary, test_size=0.2, random_state=42)\n", "\n", "# Standardize the features\n", "scaler = StandardScaler()\n", "X_train_scaled = scaler.fit_transform(X_train)\n", "X_test_scaled = scaler.transform(X_test)\n", "\n", "# Check the shape of the data\n", "print(f\"X_train shape: {X_train_scaled.shape}\")\n", "print(f\"X_test shape: {X_test_scaled.shape}\")\n" ] } ], "metadata": { "kernelspec": { "display_name": "base", "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.12.7" } }, "nbformat": 4, "nbformat_minor": 2 }