You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
433 lines
112 KiB
Plaintext
433 lines
112 KiB
Plaintext
7 months ago
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"id": "f75621c4-16cd-4320-a777-2fadf7231c9f",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import pandas as pd\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"from sklearn.linear_model import LinearRegression\n",
|
||
|
"from sklearn.preprocessing import PolynomialFeatures"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"id": "a4f8dcc4-d866-442e-859d-7895e49acde8",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"#Load the training and test data\n",
|
||
|
"X_train=np.load('/home/unipi/v.vichi3/Desktop/X_train.npy')\n",
|
||
|
"X_test=np.load('/home/unipi/v.vichi3/Desktop/X_test.npy')\n",
|
||
|
"y_train=np.load('/home/unipi/v.vichi3/Desktop/y_train.npy')\n",
|
||
|
"y_test=np.load('/home/unipi/v.vichi3/Desktop/y_test.npy')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"id": "c1048709-1a49-4737-b1cd-7dd67033623d",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"(600000, 5) (52376, 5) (600000,) (52376,)\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"print(X_train.shape, X_test.shape, y_train.shape, y_test.shape)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"id": "0edb7d7f-e148-4612-9c7c-97c572e3cb4e",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Mean of the MOID over the training set: 0.18033655783333338\n",
|
||
|
"MSE for test data: 0.016517902853446634\n",
|
||
|
"MAE for test data: 0.1054009483071237\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"#The baseline model is the one that computes the mean of the target variable on the training set and returns, for \n",
|
||
|
"#all instances in the test set, that mean\n",
|
||
|
"y_bar=y_train.mean()\n",
|
||
|
"print(\"Mean of the MOID over the training set:\", y_bar)\n",
|
||
|
"#Compute the MSE and MAE\n",
|
||
|
"MSE=0\n",
|
||
|
"MAE=0\n",
|
||
|
"for i in range(len(y_test)):\n",
|
||
|
" MSE += (y_test[i]-y_bar)**2\n",
|
||
|
" MAE += abs(y_test[i]-y_bar)\n",
|
||
|
"MAE=MAE/len(y_test)\n",
|
||
|
"MSE=MSE/len(y_test)\n",
|
||
|
"print(\"MSE for test data:\", MSE)\n",
|
||
|
"print(\"MAE for test data:\", MAE)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"id": "f4d08069-349a-4665-99e1-96b37e00c60e",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGxCAYAAACwbLZkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABAhklEQVR4nO3de3RU1d3/8c8kIQm3hHJLgIQQJJUoIpIoBkUi2kSgtojPI2gFbaOAAoI8VqVQUaoNXkqxVhA0SKmKtGJd1FI1CiKKN2JivVBFBUIwMYK/JoiQmGT//kgzOrkxM5mZM2fm/Vpr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6amnnlJKSopf3qM9vXr10ptvviljjEtAUllZqbq6Omf+evXqpbq6Oh0+fNglIKmoqHB5vR/84AeKjIzUtGnTNHv27FbfMzU11Q9HAtgfwQhgAyUlJZKkPn36SGqcwRIVFaXIyEhnmmPHjunPf/5zm68RGRmpUaNGaejQoXr88cf1zjvvaOrUqfrxj3+sJ598UvX19Ro1apRfj+P7cnNzFRUVpU8//VSXXnppwN63yQUXXKC//OUveuaZZ3TJJZc4t69fv975d0k6//zzdc899+jxxx/XDTfc4Ez3xBNPuLxely5ddP7556u4uFjDhw9vs6UJQEsEI0CQef/991VXVyepsen/6aefVmFhoS655BLnlfXEiRO1fPlyXXHFFZoxY4YOHz6s++67z9kV0uShhx7S1q1bNXHiRA0cOFDHjx/X2rVrJUkXXnihJGnq1Kl6/PHHNWHCBM2bN09nnXWWOnXqpLKyMm3btk0//elPXU7WvjJo0CAtXbpUixYt0meffeZcT+WLL77QW2+9pa5du+qOO+7w+fs2mT59uh588EFdddVV2rdvn0477TS9+uqr+u1vf6sJEyY4yycnJ0fnnXeebr75Zh09elSZmZl67bXXWg387r//fp177rkaM2aMrrvuOg0aNEhHjhzRJ598or///e8uM4kAfIdgBAgyP//5z52/x8fHKzU1VcuXL9f111/v3D5u3DitXbtWd999ty6++GINGDBA1157rfr27au8vDxnuhEjRuiFF17QkiVLVFFRoW7dumnYsGHavHmzcnJyJDW2mGzevFn333+//vznPys/P19RUVFKSkrS2LFjddppp/ntWBcuXKhTTjlF999/vzZs2KCamholJibqzDPP1KxZs/z2vlLj+i3btm3TokWLdO+99+rLL7/UgAEDdNNNN7lMwY2IiNDmzZu1YMEC3XPPPaqtrdU555yjLVu2aOjQoS6vecopp+idd97Rb37zGy1evFiVlZXq0aOH0tLSNGHCBL8eD2BnDmOarZAEAAAQQEztBQAAliIYAQAAliIYAQAAliIYAQAAliIYAQAAliIYAQAAlrLFOiMNDQ36/PPP1b179xb3kQAAAMHJGKMjR46of//+7d5vyhbByOeff67k5GSrswEAALxw4MABJSUltfl3WwQjTTfqOnDggOLi4izODQAAcEd1dbWSk5NPeMNNWwQjTV0zcXFxBCMAANjMiYZYMIAVAABYimAEAABYimAEAABYyhZjRgAAoccYo7q6OtXX11udFXgpMjJSUVFRHV52g2AEABBwtbW1Ki8v1zfffGN1VtBBXbp0Ub9+/RQdHe31axCMAAACqqGhQXv37lVkZKT69++v6OhoFrS0IWOMamtr9eWXX2rv3r1KS0trd2Gz9hCMAAACqra2Vg0NDUpOTlaXLl2szg46oHPnzurUqZP279+v2tpaxcbGevU6DGAFAFjC26toBBdf/B/5JAAAAEsRjAAAAEsRjADwqbIyadu2xp8A4A6CEQA+U1AgpaRI48Y1/iw
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(y_test[:100],'bo',markersize=3)\n",
|
||
|
"plt.plot(y_bar*np.ones((100,)), 'r*',markersize=3)\n",
|
||
|
"plt.legend(['true','predicted'],loc='upper right')\n",
|
||
|
"plt.title('Baseline model')\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"id": "e8e12366-4e6e-412a-ab2e-6bc9a40eccd4",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"R squared on test set: 0.1100957393030294\n",
|
||
|
"Intercept: 0.11164309822134315\n",
|
||
|
"Coefficients: [ 4.82630044e-02 -1.51712311e-01 1.93476860e-03 1.55072413e-06\n",
|
||
|
" 3.06501066e-06]\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"#Linear Regression\n",
|
||
|
"lin_reg=LinearRegression().fit(X_train,y_train)\n",
|
||
|
"r_sq=lin_reg.score(X_test,y_test)\n",
|
||
|
"print(\"R squared on test set:\", r_sq)\n",
|
||
|
"print(\"Intercept:\", lin_reg.intercept_)\n",
|
||
|
"print(\"Coefficients:\", lin_reg.coef_)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"id": "62de0aae-4bbf-4659-a0fe-0822fd297dbd",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"y_pred=lin_reg.intercept_+np.sum(lin_reg.coef_*X_test,axis=1)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"id": "e040808e-1800-4976-923f-d1f0d8de2db3",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"MSE for test data: 0.014699348657340645\n",
|
||
|
"MAE for test data: 0.09811802278034978\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"MSE=0\n",
|
||
|
"MAE=0\n",
|
||
|
"for i in range(len(y_test)):\n",
|
||
|
" MSE += (y_test[i]-y_pred[i])**2\n",
|
||
|
" MAE += abs(y_test[i]-y_pred[i])\n",
|
||
|
"MAE=MAE/len(y_test)\n",
|
||
|
"MSE=MSE/len(y_test)\n",
|
||
|
"print(\"MSE for test data:\", MSE)\n",
|
||
|
"print(\"MAE for test data:\", MAE)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 12,
|
||
|
"id": "bbb18511-4532-432f-ada9-6eefd790b0a5",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGxCAYAAACwbLZkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYX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bMCIESOwZMkShIeHY9OmTfjuu+8AAD4+rbcyZ2RkYOvWrRgyZAiefPJJ9OnTB1arFcXFxdixYweeeuopDBgwAM8++yxKS0sxfPhwREZG4vz583jllVfg5+eH5ORkAMC9996L+Ph4JCYmomPHjjh16hRWrFiB6OjoZid0CwsLwzPPPIOnn34aEyZMwLhx43Du3DksXrwYAQEB9pFDRN6OwQiRh8yZM6fJ5fXDX12xZs0a3HbbbVizZg1WrVoFq9WKLl26YNCgQejfvz8AW2Dw4YcfYsaMGZgyZQp8fX1x55134tNPP0XXrl1dLkNzfv/732PAgAFYvnw5pk2bht69e+Prr7/Gn//8ZyxYsAAVFRUICwtDbGysQ2DWpUsX7N69GxkZGUhPT0dQUBDuv/9+LFmyBBMnTrR3im1JcHAw9u7di6VLl2Lt2rUoLCxEYGAgunbtijvvvBPdunUDAAwYMAAHDx7EnDlz8NNPPyEsLAyJiYnYuXMnbrrpJgDAHXfcga1bt2L9+vWoqqpCREQE7rrrLjzzzDONhkRfa968eejUqRNeffVVbNmyBYGBgRg6dCheeOEFr5iVlkgKkxBCqF0IIiKpJk+ejM2bN+PcuXMtNvMQkX4wM0JEmrV
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(y_test[:100],'bo',markersize=3)\n",
|
||
|
"plt.plot(y_pred[:100], 'r*',markersize=3)\n",
|
||
|
"plt.legend(['true','predicted'],loc='upper right')\n",
|
||
|
"plt.title('Linear Regression')\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 13,
|
||
|
"id": "ad14da90-4d4b-4c7d-b2e1-1079a72b1dbd",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"#Polynomial Regression, d=2\n",
|
||
|
"X_train2=PolynomialFeatures(degree=2,include_bias=False).fit_transform(X_train)\n",
|
||
|
"X_test2=PolynomialFeatures(degree=2,include_bias=False).fit_transform(X_test)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 14,
|
||
|
"id": "e53b6e8d-688d-4672-9144-ce708f0e4aaf",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"R squared on test set: 0.27590125893584405\n",
|
||
|
"Number of parameters: 21\n",
|
||
|
"Intercept: -0.06682331717498041\n",
|
||
|
"Coefficients: [ 2.64761936e-01 -3.68484985e-01 1.98222192e-03 3.49081805e-08\n",
|
||
|
" -2.11007545e-05 5.18185781e-02 -6.50491717e-01 -8.39355649e-04\n",
|
||
|
" 3.53009628e-06 -1.87802540e-06 1.04755036e+00 8.00918631e-03\n",
|
||
|
" -1.17843565e-05 1.49267806e-05 -3.71225082e-05 -7.21465016e-08\n",
|
||
|
" -2.60640620e-08 9.40777227e-10 1.35524373e-08 4.81669732e-08]\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"pol_reg2=LinearRegression().fit(X_train2,y_train)\n",
|
||
|
"print(\"R squared on test set:\", pol_reg2.score(X_test2,y_test))\n",
|
||
|
"print(\"Number of parameters:\", len(pol_reg2.coef_)+1)\n",
|
||
|
"print(\"Intercept:\", pol_reg2.intercept_)\n",
|
||
|
"print(\"Coefficients:\", pol_reg2.coef_)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 15,
|
||
|
"id": "6ef45f92-8495-45ef-8d16-ebfed26cd02e",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"y_pred2=pol_reg2.predict(X_test2)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 16,
|
||
|
"id": "c3710a93-8fe2-4337-b680-4b560bd69cd5",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"MSE for test data: 0.011960589837953305\n",
|
||
|
"MAE for test data: 0.08473643514764896\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"MSE=0\n",
|
||
|
"MAE=0\n",
|
||
|
"for i in range(len(y_test)):\n",
|
||
|
" MSE += (y_test[i]-y_pred2[i])**2\n",
|
||
|
" MAE += abs(y_test[i]-y_pred2[i])\n",
|
||
|
"MAE=MAE/len(y_test)\n",
|
||
|
"MSE=MSE/len(y_test)\n",
|
||
|
"print(\"MSE for test data:\", MSE)\n",
|
||
|
"print(\"MAE for test data:\", MAE)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 17,
|
||
|
"id": "38dc8afc-a400-43b6-965b-b2da89e2ba2c",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGxCAYAAACwbLZkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABQT0lEQVR4nO3de1xUdf4/8NcwXEXACwoqhJioKJkKaViKV0jt4qqb6ab4jVZt00RrM9My3QpLt7RWzQvefmZaYq2pW84mmqVWIlZeUtxQwCBXS8BUUObz+2OWyYEZmBnOzDlnzuv5eMxD53Bm5jNnzuV9Pp/35/PRCSEEiIiIiGTiJXcBiIiISNsYjBAREZGsGIwQERGRrBiMEBERkawYjBAREZGsGIwQERGRrBiMEBERkawYjBAREZGsGIwQERGRrBiMkCqtW7cOOp3O/PD29kZERAT+7//+D+fPn3f4/fr164d+/fpJX1AZ7N27F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VmYORqo9//zzOHfuHFavXo2VK1ciLy8PDzzwgEU7ekZGBtLS0tClSxds27YNS5YswXfffYfExMRan3Pjxg2MGDECw4YNwz//+U8MGTIEs2bNwvPPP4/U1FQ89thj+PDDD9GxY0dMmDABOTk5dW6Xs2fPomPHjli8eDE+/fRTvPbaayguLsZdd92Fixcv2r1965Ofnw8A6NChg3nZiRMncNddd+HYsWP4+9//jh07dmDYsGF46qmnLGpPiouLkZSUhFOnTmH58uXYsGEDysvLMWXKFKufVVxcjEcffRRjx47Frl278Je//AVXr15FUlIS1q9fj6eeegr/+te/MHPmTKxbtw4PPvggqicpP3jwIEaPHo127dph8+bN2LlzJ1588UXcvHnT/P6vv/46XnrpJYwZMwY7d+7Eli1bkJaWVmcgCzj+Oz/44IMYOHAg/vnPf+Kxxx7Dm2++iddee82h7V7ts88+w0MPPYSgoCBs3rwZCxcuxPvvv4+1a9fWWreqqgo3b96s92E0Guv93D179sDb29vidydyiCBSobVr1woA4tChQ+LGjRuivLxc7NixQ7Ro0UIEBQWJkpIS8cknnwgA4vXXX7d47ZYtWwQAsXLlSvOypKQkkZSUZH5eVlYmgoKCxLRp0yxe27lzZ9G/f3/z8+zsbAFADB061GK9999/XwAQBw8eFEII8euvv4qAgIBa6xUUFAg/Pz8xduxY87LU1FQBQGRlZZmX3bhxQ7Ro0UIAEEeOHDEvv3TpktDr9WLGjBm1ypSdnW1z+928eVNcuXJFBAYGiiVLljj02lvX27Jli7hx44a4evWq+PLLL0XHjh1F586dxa+//mpeNyUlRURERIjS0lKL95gyZYrw9/cXv/zyixBCiL/+9a9Cp9OJ48ePW6yXkpJSq0xJSUkCgPjss88s1s3IyBBeXl7im2++sVi+detWAUDs2rVLCCHEokWLBABx+fJlm9/x/vvvF926datzO1Tvh/n5+UII537n999/32LdoUOHio4dO9b5ubb06tVLtG7dWly7ds28rKysTDRr1kzUPN1Xb8P6HqmpqXV+5qeffiq8vLzE9OnTnSozkRBCsGaEVO3uu++Gj48PgoKCcP/99yM8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QEBmDNnDt5++20888wzaNq0KfR6PcaNG1crz6ZadQDSvHnzWomvAFBSUmL1ddbGzQgNDUVAQIDNLqa3bueHHnoIDz30ECoqKnDo0CFkZGRg7NixaNu2LRITE+Ht7Y0ZM2ZgxowZuHz5Mv7973/j+eefR0pKCgoLC6323JHzd27atCl0Op3V7WVt2cCBA7Fv37563zc1NRXr1q2zWJabm4tBgwYhKioKu3f
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(y_test[:100],'bo',markersize=3)\n",
|
||
|
"plt.plot(y_pred2[:100], 'r*',markersize=3)\n",
|
||
|
"plt.legend(['true','predicted'],loc='upper right')\n",
|
||
|
"plt.title('Polynomial Regression, d=2')\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 18,
|
||
|
"id": "ca6fc0f5-e6f0-4d55-a2ba-40acdbbf4151",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"#Polynomial Regression, d=3\n",
|
||
|
"X_train3=PolynomialFeatures(degree=3,include_bias=False).fit_transform(X_train)\n",
|
||
|
"X_test3=PolynomialFeatures(degree=3,include_bias=False).fit_transform(X_test)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 19,
|
||
|
"id": "acbe7bca-3b74-4099-acbe-e1349f988f50",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"R squared on test set: 0.408933403538129\n",
|
||
|
"Number of parameters: 56\n",
|
||
|
"Intercept: -0.0642778564287125\n",
|
||
|
"Coefficients: [-4.85030431e-01 2.35254231e+00 2.56156230e-03 -1.73008136e-04\n",
|
||
|
" 1.36437760e-04 6.12894758e-01 -2.20816518e+00 -1.05639652e-03\n",
|
||
|
" 2.00183667e-05 5.91435833e-04 -1.08031099e+00 8.96710234e-03\n",
|
||
|
" 4.86786144e-05 -2.75426884e-03 -5.23946253e-05 3.06615778e-07\n",
|
||
|
" 7.22203296e-07 3.07131064e-07 1.02830028e-06 -5.00502751e-07\n",
|
||
|
" 1.14320320e-02 -9.19801964e-01 1.26268262e-04 2.32567799e-06\n",
|
||
|
" 3.17366059e-06 4.04507073e+00 -1.47748622e-03 -2.59277724e-05\n",
|
||
|
" -1.10312486e-05 9.63613516e-06 1.17647833e-07 1.74207575e-07\n",
|
||
|
" -2.33445282e-08 -3.45841003e-08 -1.66442399e-06 -2.61561493e+00\n",
|
||
|
" 6.85840566e-03 2.45631773e-05 -3.37029852e-05 -9.50305201e-05\n",
|
||
|
" -5.05909782e-07 5.99063352e-08 -7.11912397e-08 -3.32265493e-10\n",
|
||
|
" 7.80788118e-06 3.42736622e-07 -3.37940292e-09 -4.19296109e-09\n",
|
||
|
" 5.19863930e-10 -1.59982882e-09 -1.38488071e-09 2.34894881e-11\n",
|
||
|
" -1.37425749e-09 -1.11708820e-09 -4.76537004e-11]\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"pol_reg3=LinearRegression().fit(X_train3,y_train)\n",
|
||
|
"print(\"R squared on test set:\", pol_reg3.score(X_test3,y_test))\n",
|
||
|
"print(\"Number of parameters:\", len(pol_reg3.coef_)+1)\n",
|
||
|
"print(\"Intercept:\", pol_reg3.intercept_)\n",
|
||
|
"print(\"Coefficients:\", pol_reg3.coef_)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 20,
|
||
|
"id": "dc28385e-5d15-4286-aa18-50ce4a37b29d",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"y_pred3=pol_reg3.predict(X_test3)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 21,
|
||
|
"id": "52c51b93-7d1b-48d2-a530-2e7b4131706f",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"MSE for test data: 0.009763178315716749\n",
|
||
|
"MAE for test data: 0.07445845502584257\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"MSE=0\n",
|
||
|
"MAE=0\n",
|
||
|
"for i in range(len(y_test)):\n",
|
||
|
" MSE += (y_test[i]-y_pred3[i])**2\n",
|
||
|
" MAE += abs(y_test[i]-y_pred3[i])\n",
|
||
|
"MAE=MAE/len(y_test)\n",
|
||
|
"MSE=MSE/len(y_test)\n",
|
||
|
"print(\"MSE for test data:\", MSE)\n",
|
||
|
"print(\"MAE for test data:\", MAE)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 22,
|
||
|
"id": "40e6b8a7-4b46-4e10-99b9-2187b84fcb7a",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGxCAYAAACwbLZkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABQfElEQVR4nO3de1xUdf4/8NcwwIAImKKggogrKkqmQhma4hVSu7jqZropbphaaaJdzLRMt8LKSmvVvODtZ15KrTV1SzYRNa1NwsxLXr6hgMGSVoA3UObz+2OW0WEGmMuZOefMvJ6PxzxwjmdmPnNm5pz3eX8+n/fRCCEEiIiIiGTiJXcDiIiIyLMxGCEiIiJZMRghIiIiWTEYISIiIlkxGCEiIiJZMRghIiIiWTEYISIiIlkxGCEiIiJZMRghIiIiWTE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YNGoTFixdj0KBB2L59O+bOnQutVmtzO6uDlaKiIrP/++WXXxASEmLzc1qrtLQUO3bswJw5c/Diiy8al1dUVOC3335z6LnbtGljclDy9/fH7Nmz8cEHH+C5557DHXfcAa1WizFjxpiNs6lWHYA0adLEbOArABQXF1t8nKW6GSEhIfD398eqVassPub27fzwww/j4YcfRkVFBb755hukp6dj9OjRaN26NRISEuDt7Y3p06dj+vTp+OOPP/Dvf/8bL730EpKTk1FQUGBx5o6cn/Mdd9wBjUZjcXtZWta/f39kZ2fX+7wpKSlYs2ZNnevEx8fDy8s
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(y_test[:100],'bo',markersize=3)\n",
|
||
|
"plt.plot(y_pred3[:100], 'r*',markersize=3)\n",
|
||
|
"plt.legend(['true','predicted'],loc='upper right')\n",
|
||
|
"plt.title('Polynomial Regression, d=3')\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"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.9.19"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 5
|
||
|
}
|