fix cyfi445 lab 7

This commit is contained in:
Frank Xu
2025-10-02 09:45:16 -04:00
parent b3a07c5bcc
commit 5f3192c3d1

View File

@@ -217,14 +217,20 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"id": "3aeb88da",
"metadata": {},
"outputs": [],
"source": [
"# Scale features\n",
"scaler = StandardScaler()\n",
"# fit() computes the mean and std of each feature using the training data only.\n",
"# transform() applies the standardization formula to scale the data.\n",
"# fit_transform() does both in one step.\n",
"X_train = scaler.fit_transform(X_train)\n",
"# Very important: we do not fit again on the test set.\n",
"# Instead, we use the same mean and std from the training set (stored inside scaler) to transform the test data.\n",
"# This prevents data leakage — making sure the test set stays “unseen” during training.\n",
"X_test = scaler.transform(X_test)\n",
"\n",
"# Convert to PyTorch tensors\n",