You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

691 lines
43 KiB

2 years ago
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='https://www.udemy.com/user/joseportilla/'><img src='../Pierian_Data_Logo.png'/></a>\n",
"___\n",
"<center><em>Copyright by Pierian Data Inc.</em></center>\n",
"<center><em>For more information, visit us at <a href='http://www.pieriandata.com'>www.pieriandata.com</a></em></center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Support Vector Machines\n",
"## SVM - Regression"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The concrete slump test measures the consistency of fresh concrete before it sets. It is performed to check the workability of freshly made concrete, and therefore the ease with which concrete flows. It can also be used as an indicator of an improperly mixed batch.\n",
"\n",
"<img src=\"Types_of_concrete_slump.jpg\">\n",
"\n",
"Our data set consists of various cement properties and the resulting slump test metrics in cm. Later on the set concrete is tested for its compressive strength 28 days later.\n",
"\n",
"Input variables (7)(component kg in one M^3 concrete):\n",
"* Cement\n",
"* Slag\n",
"* Fly ash\n",
"* Water\n",
"* SP\n",
"* Coarse Aggr.\n",
"* Fine Aggr.\n",
"\n",
"Output variables (3):\n",
"* SLUMP (cm)\n",
"* FLOW (cm)\n",
"* **28-day Compressive Strength (Mpa)**\n",
"\n",
"Data Source: https://archive.ics.uci.edu/ml/datasets/Concrete+Slump+Test\n",
"\n",
"*Credit: Yeh, I-Cheng, \"Modeling slump flow of concrete using second-order regressions and artificial neural networks,\" Cement and Concrete Composites, Vol.29, No. 6, 474-480, 2007.*"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('../DATA/cement_slump.csv')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Cement</th>\n",
" <th>Slag</th>\n",
" <th>Fly ash</th>\n",
" <th>Water</th>\n",
" <th>SP</th>\n",
" <th>Coarse Aggr.</th>\n",
" <th>Fine Aggr.</th>\n",
" <th>SLUMP(cm)</th>\n",
" <th>FLOW(cm)</th>\n",
" <th>Compressive Strength (28-day)(Mpa)</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>273.0</td>\n",
" <td>82.0</td>\n",
" <td>105.0</td>\n",
" <td>210.0</td>\n",
" <td>9.0</td>\n",
" <td>904.0</td>\n",
" <td>680.0</td>\n",
" <td>23.0</td>\n",
" <td>62.0</td>\n",
" <td>34.99</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>163.0</td>\n",
" <td>149.0</td>\n",
" <td>191.0</td>\n",
" <td>180.0</td>\n",
" <td>12.0</td>\n",
" <td>843.0</td>\n",
" <td>746.0</td>\n",
" <td>0.0</td>\n",
" <td>20.0</td>\n",
" <td>41.14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>162.0</td>\n",
" <td>148.0</td>\n",
" <td>191.0</td>\n",
" <td>179.0</td>\n",
" <td>16.0</td>\n",
" <td>840.0</td>\n",
" <td>743.0</td>\n",
" <td>1.0</td>\n",
" <td>20.0</td>\n",
" <td>41.81</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>162.0</td>\n",
" <td>148.0</td>\n",
" <td>190.0</td>\n",
" <td>179.0</td>\n",
" <td>19.0</td>\n",
" <td>838.0</td>\n",
" <td>741.0</td>\n",
" <td>3.0</td>\n",
" <td>21.5</td>\n",
" <td>42.08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>154.0</td>\n",
" <td>112.0</td>\n",
" <td>144.0</td>\n",
" <td>220.0</td>\n",
" <td>10.0</td>\n",
" <td>923.0</td>\n",
" <td>658.0</td>\n",
" <td>20.0</td>\n",
" <td>64.0</td>\n",
" <td>26.82</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Cement Slag Fly ash Water SP Coarse Aggr. Fine Aggr. SLUMP(cm) \\\n",
"0 273.0 82.0 105.0 210.0 9.0 904.0 680.0 23.0 \n",
"1 163.0 149.0 191.0 180.0 12.0 843.0 746.0 0.0 \n",
"2 162.0 148.0 191.0 179.0 16.0 840.0 743.0 1.0 \n",
"3 162.0 148.0 190.0 179.0 19.0 838.0 741.0 3.0 \n",
"4 154.0 112.0 144.0 220.0 10.0 923.0 658.0 20.0 \n",
"\n",
" FLOW(cm) Compressive Strength (28-day)(Mpa) \n",
"0 62.0 34.99 \n",
"1 20.0 41.14 \n",
"2 20.0 41.81 \n",
"3 21.5 42.08 \n",
"4 64.0 26.82 "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Cement 0.445656\n",
"Slag -0.331522\n",
"Fly ash 0.444380\n",
"Water -0.254320\n",
"SP -0.037909\n",
"Coarse Aggr. -0.160610\n",
"Fine Aggr. -0.154532\n",
"SLUMP(cm) -0.223499\n",
"FLOW(cm) -0.124189\n",
"Compressive Strength (28-day)(Mpa) 1.000000\n",
"Name: Compressive Strength (28-day)(Mpa), dtype: float64"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.corr()['Compressive Strength (28-day)(Mpa)']"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<AxesSubplot:>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAhQAAAGrCAYAAACYDg7YAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAABN7klEQVR4nO3dd7ycZZ3+8c9F6B0REeklgNQAIQKigqKiIqggRSyIiP5c27q6iwurrq4r9l6IiGADEURZ6S2C9ACBECB0kKJIL1JCzvX747kPGYZzknMyz8ycOXO9X695ZZ77eeb53pOcnPnOXWWbiIiIiFYs0u0KRERERO9LQhEREREtS0IRERERLUtCERERES1LQhEREREtS0IRERERLUtCERERMY5IOkrSfZKuHea8JH1P0s2SrpG0dR1xk1BERESML0cDu87n/JuAieVxMPDjOoImoYiIiBhHbJ8PPDifS/YAfuHKJcCKklZrNW4SioiIiP6yOvDXhuO7SllLFm31BhHj1cDfNuzIuvQ7f+CgToQBYOmr7+pYrBsOWbsjcVa+Sh2JA7DizU91LNY9r1qqY7GeWa5joRhYojPbPay44fy+oNfvyjf/T0s/iKP5fTNhtZs+RNVVMWiq7amtxK9DEoqIiIguG2BgxNeW5KGVBOJuYM2G4zVKWUvS5REREdFlcz0w4kcNTgbeW2Z7bAc8YvveVm+aFoqIiIguG6C+riBJxwI7AS+WdBfweWAxANs/AU4F3gzcDPwTeH8dcZNQREREdNkczx3xtQsaXWN7vwWcN/AvIw44QkkoIiIiuqzOFopuSUIRERHRZXPHQUKRQZnREZJeKuk4SbdIukLSqZI27EI9/rPTMSMiFmQAj/gxViWhiLaTJOAkYJrt9W1vA3wWWLUL1UlCERFjzlx7xI+xKglFdMLOwJwyuhgA21fbvkDSZyRdXjao+W8ASetIukHS0ZJulPRrSbtIulDSTZK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ThgD+C6hms+CPzQ9kMAtu9rNWi6PGJMkbSIpJskrdJwfPPgccN1UyRdLOkqSRdJ2qiUbyrpMkkzJF1TsnCACZJ+Wpr2zpS0VIffWkTEsOZaI36MwOrAXxuO7ypljTYENpR0oaRLJO3a6ntIQhHdsFT5wJ8h6aTGE7YHgF8B+5eiXYCrbf+j6R43AK+yvRXwOeB/S/mHge+WFpDJVP+RACZSZeObAg8Dew5VMUkHS5ouafpfn7i2lfcYETFiA15kxI/G31PlcfBChFyU6vfiTsB+wE8lrdjKe0iXR3TDC7o8mhwF/BH4DnAg8PMhrlkBOKa0QBgY3NDhYuBQSWsAv7d9kySA22zPKNdcQTVm4wVsTwWmArxpjY97xO8oIqIFz45iDEXj76lh3A2s2XC8RilrdBdwqe05wG2SbqRKMC4fcUWapIUixhzbfwX+Lum1VH2Bpw1x2ZeA88pAy7cCS5bX/gbYHXgSOLXcA+DphtfOJcl0RIwhNc/yuByYKGldSYsD+wInN13zB6rWCSS9mKoL5NZW3kN+qcZYdSRV18cvbc8d4vwKzMu4DxgslLQecKvt70laC9iCFv+TRES0W52zPGw/K+mjwBnABOAo27MkfRGYbvvkcu4Nkq6j+pL1GdstbdGahCLGqpOpujqG6u4A+BpVl8dhwCkN5XsD75E0B/gb1diK5dtZ0YiIVtW9UqbtU4FTm8o+1/DcwKfKoxZJKKLjbC87RNk0YFpD0ZZUgzFvGOYeF1M10Q06rJQfDhzedPmDwHNrUNj+xsLUOyKiXWqeNtoVSShizCmruv0/5s30iIgY17KXR0QbDNPKEBExbj070PtzJJJQREREdFlaKCIiIqJlGUMRMY7dcMjaHYmz/E2da+rc+QMHdSzWeT87smOxdvi3D3U
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"sns.heatmap(df.corr(),cmap='viridis')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Cement', 'Slag', 'Fly ash', 'Water', 'SP', 'Coarse Aggr.',\n",
" 'Fine Aggr.', 'SLUMP(cm)', 'FLOW(cm)',\n",
" 'Compressive Strength (28-day)(Mpa)'],\n",
" dtype='object')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.columns"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Train | Test Split\n",
"\n",
"Alternatively you could also set this up as a pipline, something like:\n",
"\n",
" >>> from sklearn.pipeline import make_pipeline\n",
" >>> from sklearn.preprocessing import StandardScaler\n",
" >>> from sklearn.svm import SVR\n",
"\n",
" >>> clf = make_pipeline(StandardScaler(), SVR())"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Cement', 'Slag', 'Fly ash', 'Water', 'SP', 'Coarse Aggr.',\n",
" 'Fine Aggr.', 'SLUMP(cm)', 'FLOW(cm)',\n",
" 'Compressive Strength (28-day)(Mpa)'],\n",
" dtype='object')"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.columns"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"X = df.drop('Compressive Strength (28-day)(Mpa)',axis=1)\n",
"y = df['Compressive Strength (28-day)(Mpa)']"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=101)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.preprocessing import StandardScaler"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"scaler = StandardScaler()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"scaled_X_train = scaler.fit_transform(X_train)\n",
"scaled_X_test = scaler.transform(X_test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Support Vector Machines - Regression\n",
"\n",
"There are three different implementations of Support Vector Regression: SVR, NuSVR and LinearSVR. LinearSVR provides a faster implementation than SVR but only considers the linear kernel, while NuSVR implements a slightly different formulation than SVR and LinearSVR. See [Implementation details](https://scikit-learn.org/stable/modules/svm.html#svm-implementation-details) for further details."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.svm import SVR,LinearSVR"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Setting C: C is 1 by default and its a reasonable default choice. If you have a lot of noisy observations you should decrease it: decreasing C corresponds to more regularization.\n",
"\n",
"LinearSVC and LinearSVR are less sensitive to C when it becomes large, and prediction results stop improving after a certain threshold. Meanwhile, larger C values will take more time to train, sometimes up to 10 times longer\n",
"\n",
"Epsilon: https://stats.stackexchange.com/questions/259018/meaning-of-epsilon-in-svm-regression"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"base_model = SVR()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"SVR()"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"base_model.fit(scaled_X_train,y_train)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"base_preds = base_model.predict(scaled_X_test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Evaluation"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.metrics import mean_absolute_error,mean_squared_error"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5.236902091259178"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_absolute_error(y_test,base_preds)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6.695914838327133"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.sqrt(mean_squared_error(y_test,base_preds))"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"36.26870967741935"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y_test.mean()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Grid Search in Attempt for Better Model"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"param_grid = {'C':[0.001,0.01,0.1,0.5,1],\n",
" 'kernel':['linear','rbf','poly'],\n",
" 'gamma':['scale','auto'],\n",
" 'degree':[2,3,4],\n",
" 'epsilon':[0,0.01,0.1,0.5,1,2]}"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import GridSearchCV"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"svr = SVR()\n",
"grid = GridSearchCV(svr,param_grid=param_grid)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"GridSearchCV(estimator=SVR(),\n",
" param_grid={'C': [0.001, 0.01, 0.1, 0.5, 1], 'degree': [2, 3, 4],\n",
" 'epsilon': [0, 0.01, 0.1, 0.5, 1, 2],\n",
" 'gamma': ['scale', 'auto'],\n",
" 'kernel': ['linear', 'rbf', 'poly']})"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"grid.fit(scaled_X_train,y_train)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'C': 1, 'degree': 2, 'epsilon': 2, 'gamma': 'scale', 'kernel': 'linear'}"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"grid.best_params_"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"grid_preds = grid.predict(scaled_X_test)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.5128012210762365"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_absolute_error(y_test,grid_preds)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.178210305119858"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.sqrt(mean_squared_error(y_test,grid_preds))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Great improvement!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}