File size: 7,245 Bytes
7141391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [],
      "metadata": {
        "id": "v79as6XRiDqE"
      }
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "daba9903"
      },
      "source": [
        "# VO2 Max Prediction\n",
        "\n",
        "This notebook demonstrates the process of predicting VO2 max using a dataset containing various physiological and training-related features.\n",
        "\n",
        "**Steps:**\n",
        "\n",
        "1.  **Setup and Imports**: Install necessary libraries and import modules.\n",
        "2.  **Import and Inspect Dataset**: Load and explore the initial dataset.\n",
        "3.  **Clean and Prepare Data**: Preprocess the data for analysis.\n",
        "4.  **Augment with Synthetic Features**: Add simulated features to enrich the dataset.\n",
        "5.  **Export Augmented Data Set**: Export augmented dataset for use in training pipeline.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Setup and Imports"
      ],
      "metadata": {
        "id": "8pnzsYhMmn5z"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {
        "id": "czA2E20LIfpT"
      },
      "outputs": [],
      "source": [
        "!pip -q install numpy pandas scikit-learn streamlit joblib matplotlib\n",
        "\n",
        "import numpy as np, pandas as pd\n",
        "import os\n",
        "from numpy.random import default_rng\n",
        "rng = default_rng(42)\n",
        "\n",
        "import os, json, joblib, math"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Import and Inspect Dataset"
      ],
      "metadata": {
        "id": "Kkq_ss4qOwQk"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "!ls -lh /content\n",
        "df = pd.read_csv(\"/content/sample_data/SPO2Max dataset/Baseline_Data_Insight1b.csv\")\n",
        "df.head(), df.info(), df.shape"
      ],
      "metadata": {
        "id": "7_eXmAotIxF5"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Clean and Prepare Data"
      ],
      "metadata": {
        "id": "qy_LxfnvOeLD"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df.columns = df.columns.str.strip().str.replace(\" \", \"_\").str.lower()\n",
        "\n",
        "# select relevant fields\n",
        "cols = [\"age\",\"sex\",\"height\",\"mass\",\"total_lean_mass\",\"bmi\",\"wbtpf\",\"vo2max_rel\"]\n",
        "df = df[cols].dropna()\n",
        "\n",
        "# rename for consistency with earlier runbook\n",
        "df = df.rename(columns={\n",
        "    \"mass\": \"weight_kg\",\n",
        "    \"height\": \"height_cm\",\n",
        "    \"vo2max_rel\": \"vo2max\"\n",
        "})\n",
        "\n",
        "# encode sex\n",
        "if df[\"sex\"].dtype == \"object\":\n",
        "    df[\"sex\"] = df[\"sex\"].str.upper().map({\"M\": 1, \"F\": 0})\n",
        "\n",
        "df.head(), df.shape\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "5IGi3v-FNzsH",
        "outputId": "7666ed41-1ee2-4590-f272-c779cbc134e8"
      },
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(    age  sex  height_cm  weight_kg  total_lean_mass        bmi      wbtpf  \\\n",
              " 0  24.2    1      174.0      103.9        64.940172  34.317611  38.403303   \n",
              " 1  29.6    0      169.0       64.3        45.163956  22.513217  29.592141   \n",
              " 2  32.9    1      188.4      115.2        79.401800  32.455678  32.061826   \n",
              " 3  26.7    0      161.1       83.3        47.708081  32.096222  43.168116   \n",
              " 4  22.5    0      162.8       61.8        45.926730  23.317376  26.905369   \n",
              " \n",
              "    vo2max  \n",
              " 0    25.3  \n",
              " 1    36.6  \n",
              " 2    35.8  \n",
              " 3    30.4  \n",
              " 4    56.1  ,\n",
              " (424, 8))"
            ]
          },
          "metadata": {},
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Augment with synthetic features\n",
        "\n",
        "Since this real data lacks sleep, HR, training, we are simulating those. We will merge these synthetic features on top so the model can train with richer input. For roadmap, we will collect sleep, HR and training data from wearables"
      ],
      "metadata": {
        "id": "Pup47npPPecI"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "N = len(df)\n",
        "rng = np.random.default_rng(123)\n",
        "\n",
        "# synthetic HR / recovery\n",
        "df[\"resting_hr\"] = (rng.normal(60, 6, N) + 0.1*(df[\"bmi\"] - 24)).clip(45, 95)\n",
        "df[\"max_hr\"] = (220 - df[\"age\"]) + rng.normal(0, 3, N)\n",
        "df[\"hr_recovery_1min\"] = (30 + rng.normal(0, 4, N) - 0.05*(df[\"age\"] - 30)).clip(10, 55)\n",
        "\n",
        "# synthetic training load\n",
        "df[\"training_hours_week\"] = rng.normal(4, 2, N).clip(0, 10)\n",
        "df[\"avg_intensity\"] = rng.integers(3, 9, N)\n",
        "df[\"rest_days\"] = rng.integers(0, 3, N)\n",
        "\n",
        "# synthetic sleep / recovery features\n",
        "df[\"sleep_hours_last_night\"] = rng.normal(7, 1, N).clip(4, 9)\n",
        "df[\"avg_sleep_hours_week\"] = (df[\"sleep_hours_last_night\"] + rng.normal(0, 0.7, N)).clip(5, 8)\n",
        "df[\"sleep_quality_score\"] = (rng.normal(70, 10, N)\n",
        "                             - 0.3*(df[\"resting_hr\"] - 60)).clip(30, 95)\n",
        "df[\"resting_hr_delta\"] = df[\"resting_hr\"] - df[\"resting_hr\"].median()"
      ],
      "metadata": {
        "id": "MbgTjrVWPETF"
      },
      "execution_count": 13,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Export Augmeted Data Set"
      ],
      "metadata": {
        "id": "FgKXsPQkm3gK"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "os.makedirs(\"assets\", exist_ok=True)\n",
        "df.to_csv(\"assets/vo2_real_augmented.csv\", index=False)\n",
        "print(\"Saved → assets/vo2_real_augmented.csv\", \"rows:\", len(df))"
      ],
      "metadata": {
        "id": "YaOLkxkaRR-b",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "b2594606-453a-4786-938c-737d5b9769f7"
      },
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Saved → assets/vo2_real_augmented.csv rows: 424\n"
          ]
        }
      ]
    }
  ]
}