{ "nbformat": 4, "nbformat_minor": 5, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 3 - Swim Data Regression\n", "\n", "This notebook is self-contained. It recreates the small swim-block table used in the chapter and predicts the missing 100 m time from training-zone distribution." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from sklearn.linear_model import LinearRegression\n", "\n", "data = pd.DataFrame({\n", " \"Block\": [1, 2, 3, 4, 5, 6],\n", " \"Z0\": [35, 37, 35, 34, 32, 32],\n", " \"Z1\": [25, 35, 27, 42, 45, 47],\n", " \"Z2\": [12, 10, 10, 9, 9, 11],\n", " \"Z3\": [10, 12, 10, 10, 10, 9],\n", " \"Z4\": [2, 2, 2, 2, 2, 2],\n", " \"Z5\": [2, 3, 3, 3, 4, 4],\n", " \"Total\": [86, 99, 87, 100, 102, 105],\n", " \"100m Time\": [55.4, 54.2, 54.8, 52.9, 52.7, None],\n", "})\n", "data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "training_data = data.dropna(subset=[\"100m Time\"])\n", "features = [\"Z0\", \"Z1\", \"Z2\", \"Z3\", \"Z4\", \"Z5\"]\n", "\n", "model = LinearRegression()\n", "model.fit(training_data[features], training_data[\"100m Time\"])\n", "\n", "new_block = data.loc[data[\"100m Time\"].isna(), features]\n", "prediction = model.predict(new_block)[0]\n", "print(f\"Coefs: {model.coef_}\")\n", "print(f\"Intercept: {model.intercept_:.2f}\")\n", "print(f\"Predicted 100 m time for block 6: {prediction:.2f} s\")" ] } ] }