{
"cells": [
{
"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\n",
"%matplotlib inline "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.datasets import load_boston\n",
"from sklearn.model_selection import train_test_split"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 0 | \n",
" 1 | \n",
" 2 | \n",
" 3 | \n",
" 4 | \n",
" 5 | \n",
" 6 | \n",
" 7 | \n",
" 8 | \n",
" 9 | \n",
" 10 | \n",
" 11 | \n",
" 12 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0.00632 | \n",
" 18.0 | \n",
" 2.31 | \n",
" 0.0 | \n",
" 0.538 | \n",
" 6.575 | \n",
" 65.2 | \n",
" 4.0900 | \n",
" 1.0 | \n",
" 296.0 | \n",
" 15.3 | \n",
" 396.90 | \n",
" 4.98 | \n",
"
\n",
" \n",
" 1 | \n",
" 0.02731 | \n",
" 0.0 | \n",
" 7.07 | \n",
" 0.0 | \n",
" 0.469 | \n",
" 6.421 | \n",
" 78.9 | \n",
" 4.9671 | \n",
" 2.0 | \n",
" 242.0 | \n",
" 17.8 | \n",
" 396.90 | \n",
" 9.14 | \n",
"
\n",
" \n",
" 2 | \n",
" 0.02729 | \n",
" 0.0 | \n",
" 7.07 | \n",
" 0.0 | \n",
" 0.469 | \n",
" 7.185 | \n",
" 61.1 | \n",
" 4.9671 | \n",
" 2.0 | \n",
" 242.0 | \n",
" 17.8 | \n",
" 392.83 | \n",
" 4.03 | \n",
"
\n",
" \n",
" 3 | \n",
" 0.03237 | \n",
" 0.0 | \n",
" 2.18 | \n",
" 0.0 | \n",
" 0.458 | \n",
" 6.998 | \n",
" 45.8 | \n",
" 6.0622 | \n",
" 3.0 | \n",
" 222.0 | \n",
" 18.7 | \n",
" 394.63 | \n",
" 2.94 | \n",
"
\n",
" \n",
" 4 | \n",
" 0.06905 | \n",
" 0.0 | \n",
" 2.18 | \n",
" 0.0 | \n",
" 0.458 | \n",
" 7.147 | \n",
" 54.2 | \n",
" 6.0622 | \n",
" 3.0 | \n",
" 222.0 | \n",
" 18.7 | \n",
" 396.90 | \n",
" 5.33 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 0 1 2 3 4 5 6 7 8 9 10 \\\n",
"0 0.00632 18.0 2.31 0.0 0.538 6.575 65.2 4.0900 1.0 296.0 15.3 \n",
"1 0.02731 0.0 7.07 0.0 0.469 6.421 78.9 4.9671 2.0 242.0 17.8 \n",
"2 0.02729 0.0 7.07 0.0 0.469 7.185 61.1 4.9671 2.0 242.0 17.8 \n",
"3 0.03237 0.0 2.18 0.0 0.458 6.998 45.8 6.0622 3.0 222.0 18.7 \n",
"4 0.06905 0.0 2.18 0.0 0.458 7.147 54.2 6.0622 3.0 222.0 18.7 \n",
"\n",
" 11 12 \n",
"0 396.90 4.98 \n",
"1 396.90 9.14 \n",
"2 392.83 4.03 \n",
"3 394.63 2.94 \n",
"4 396.90 5.33 "
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = pd.DataFrame(load_boston().data)\n",
"target = pd.DataFrame(load_boston().target)\n",
"data.head()"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.preprocessing import MinMaxScaler"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 0 | \n",
" 1 | \n",
" 2 | \n",
" 3 | \n",
" 4 | \n",
" 5 | \n",
" 6 | \n",
" 7 | \n",
" 8 | \n",
" 9 | \n",
" 10 | \n",
" 11 | \n",
" 12 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0.000000 | \n",
" 0.18 | \n",
" 0.067815 | \n",
" 0.0 | \n",
" 0.314815 | \n",
" 0.577505 | \n",
" 0.641607 | \n",
" 0.269203 | \n",
" 0.000000 | \n",
" 0.208015 | \n",
" 0.287234 | \n",
" 1.000000 | \n",
" 0.089680 | \n",
"
\n",
" \n",
" 1 | \n",
" 0.000236 | \n",
" 0.00 | \n",
" 0.242302 | \n",
" 0.0 | \n",
" 0.172840 | \n",
" 0.547998 | \n",
" 0.782698 | \n",
" 0.348962 | \n",
" 0.043478 | \n",
" 0.104962 | \n",
" 0.553191 | \n",
" 1.000000 | \n",
" 0.204470 | \n",
"
\n",
" \n",
" 2 | \n",
" 0.000236 | \n",
" 0.00 | \n",
" 0.242302 | \n",
" 0.0 | \n",
" 0.172840 | \n",
" 0.694386 | \n",
" 0.599382 | \n",
" 0.348962 | \n",
" 0.043478 | \n",
" 0.104962 | \n",
" 0.553191 | \n",
" 0.989737 | \n",
" 0.063466 | \n",
"
\n",
" \n",
" 3 | \n",
" 0.000293 | \n",
" 0.00 | \n",
" 0.063050 | \n",
" 0.0 | \n",
" 0.150206 | \n",
" 0.658555 | \n",
" 0.441813 | \n",
" 0.448545 | \n",
" 0.086957 | \n",
" 0.066794 | \n",
" 0.648936 | \n",
" 0.994276 | \n",
" 0.033389 | \n",
"
\n",
" \n",
" 4 | \n",
" 0.000705 | \n",
" 0.00 | \n",
" 0.063050 | \n",
" 0.0 | \n",
" 0.150206 | \n",
" 0.687105 | \n",
" 0.528321 | \n",
" 0.448545 | \n",
" 0.086957 | \n",
" 0.066794 | \n",
" 0.648936 | \n",
" 1.000000 | \n",
" 0.099338 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 0 1 2 3 4 5 6 7 \\\n",
"0 0.000000 0.18 0.067815 0.0 0.314815 0.577505 0.641607 0.269203 \n",
"1 0.000236 0.00 0.242302 0.0 0.172840 0.547998 0.782698 0.348962 \n",
"2 0.000236 0.00 0.242302 0.0 0.172840 0.694386 0.599382 0.348962 \n",
"3 0.000293 0.00 0.063050 0.0 0.150206 0.658555 0.441813 0.448545 \n",
"4 0.000705 0.00 0.063050 0.0 0.150206 0.687105 0.528321 0.448545 \n",
"\n",
" 8 9 10 11 12 \n",
"0 0.000000 0.208015 0.287234 1.000000 0.089680 \n",
"1 0.043478 0.104962 0.553191 1.000000 0.204470 \n",
"2 0.043478 0.104962 0.553191 0.989737 0.063466 \n",
"3 0.086957 0.066794 0.648936 0.994276 0.033389 \n",
"4 0.086957 0.066794 0.648936 1.000000 0.099338 "
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sc1 = MinMaxScaler()\n",
"for i in data.columns:\n",
" data[i] = sc1_data = sc1.fit_transform(pd.DataFrame(data[i]))\n",
"data.head()\n"
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [],
"source": [
"train_data, test_data, train_target, test_target = train_test_split(data, target, random_state=42)"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 0 | \n",
" 1 | \n",
" 2 | \n",
" 3 | \n",
" 4 | \n",
" 5 | \n",
" 6 | \n",
" 7 | \n",
" 8 | \n",
" 9 | \n",
" 10 | \n",
" 11 | \n",
" 12 | \n",
"
\n",
" \n",
" \n",
" \n",
" 182 | \n",
" 0.000952 | \n",
" 0.0 | \n",
" 0.073314 | \n",
" 0.0 | \n",
" 0.211934 | \n",
" 0.688638 | \n",
" 0.919670 | \n",
" 0.142858 | \n",
" 0.086957 | \n",
" 0.011450 | \n",
" 0.553191 | \n",
" 0.992990 | \n",
" 0.085265 | \n",
"
\n",
" \n",
" 155 | \n",
" 0.039662 | \n",
" 0.0 | \n",
" 0.700880 | \n",
" 1.0 | \n",
" 1.000000 | \n",
" 0.496455 | \n",
" 0.820803 | \n",
" 0.056007 | \n",
" 0.173913 | \n",
" 0.412214 | \n",
" 0.223404 | \n",
" 0.221116 | \n",
" 0.366722 | \n",
"
\n",
" \n",
" 280 | \n",
" 0.000331 | \n",
" 0.2 | \n",
" 0.105205 | \n",
" 0.0 | \n",
" 0.119136 | \n",
" 0.816057 | \n",
" 0.634398 | \n",
" 0.324191 | \n",
" 0.173913 | \n",
" 0.055344 | \n",
" 0.244681 | \n",
" 0.975818 | \n",
" 0.056015 | \n",
"
\n",
" \n",
" 126 | \n",
" 0.004283 | \n",
" 0.0 | \n",
" 0.923387 | \n",
" 0.0 | \n",
" 0.403292 | \n",
" 0.393179 | \n",
" 0.954686 | \n",
" 0.057071 | \n",
" 0.043478 | \n",
" 0.001908 | \n",
" 0.691489 | \n",
" 0.905164 | \n",
" 0.704470 | \n",
"
\n",
" \n",
" 329 | \n",
" 0.000685 | \n",
" 0.0 | \n",
" 0.101906 | \n",
" 0.0 | \n",
" 0.154321 | \n",
" 0.531136 | \n",
" 0.147271 | \n",
" 0.371468 | \n",
" 0.130435 | \n",
" 0.463740 | \n",
" 0.457447 | \n",
" 0.945307 | \n",
" 0.154801 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 0 1 2 3 4 5 6 7 \\\n",
"182 0.000952 0.0 0.073314 0.0 0.211934 0.688638 0.919670 0.142858 \n",
"155 0.039662 0.0 0.700880 1.0 1.000000 0.496455 0.820803 0.056007 \n",
"280 0.000331 0.2 0.105205 0.0 0.119136 0.816057 0.634398 0.324191 \n",
"126 0.004283 0.0 0.923387 0.0 0.403292 0.393179 0.954686 0.057071 \n",
"329 0.000685 0.0 0.101906 0.0 0.154321 0.531136 0.147271 0.371468 \n",
"\n",
" 8 9 10 11 12 \n",
"182 0.086957 0.011450 0.553191 0.992990 0.085265 \n",
"155 0.173913 0.412214 0.223404 0.221116 0.366722 \n",
"280 0.173913 0.055344 0.244681 0.975818 0.056015 \n",
"126 0.043478 0.001908 0.691489 0.905164 0.704470 \n",
"329 0.130435 0.463740 0.457447 0.945307 0.154801 "
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"train_data.head()"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.linear_model import LinearRegression"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [],
"source": [
"reg = LinearRegression().fit(train_data, train_target)"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.metrics import mean_absolute_error, mean_squared_error, mean_squared_log_error, median_absolute_error, r2_score "
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.060939595437028"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_absolute_error(reg.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"22.098694827097976"
]
},
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_squared_error(reg.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": 79,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.122589584696989"
]
},
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"median_absolute_error(reg.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.svm import SVR"
]
},
{
"cell_type": "code",
"execution_count": 81,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n"
]
}
],
"source": [
"reg = SVR().fit(train_data, train_target)"
]
},
{
"cell_type": "code",
"execution_count": 82,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.9596221674067658"
]
},
"execution_count": 82,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_absolute_error(reg.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": 83,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"40.336929726181786"
]
},
"execution_count": 83,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_squared_error(reg.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": 84,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.5834322162465035"
]
},
"execution_count": 84,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"median_absolute_error(reg.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": 85,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.tree import DecisionTreeRegressor"
]
},
{
"cell_type": "code",
"execution_count": 86,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DecisionTreeRegressor(criterion='mse', max_depth=2, max_features=None,\n",
" max_leaf_nodes=None, min_impurity_decrease=0.0,\n",
" min_impurity_split=None, min_samples_leaf=1,\n",
" min_samples_split=2, min_weight_fraction_leaf=0.0,\n",
" presort=False, random_state=None, splitter='best')"
]
},
"execution_count": 86,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reg = DecisionTreeRegressor(max_depth=2)\n",
"reg.fit(train_data, train_target)"
]
},
{
"cell_type": "code",
"execution_count": 87,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.664502589582719\n",
"25.417194489397087\n",
"3.017499999999991\n"
]
}
],
"source": [
"print(mean_absolute_error(reg.predict(test_data), test_target))\n",
"print(mean_squared_error(reg.predict(test_data), test_target))\n",
"print(median_absolute_error(reg.predict(test_data), test_target))"
]
},
{
"cell_type": "code",
"execution_count": 88,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import GridSearchCV"
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"GridSearchCV(cv=3, error_score='raise-deprecating',\n",
" estimator=LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None,\n",
" normalize=False),\n",
" fit_params=None, iid='warn', n_jobs=None,\n",
" param_grid={'n_jobs': range(0, 10)}, pre_dispatch='2*n_jobs',\n",
" refit=True, return_train_score='warn', scoring=None, verbose=0)"
]
},
"execution_count": 89,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reg = LinearRegression()\n",
"param = {'n_jobs':range(10)}\n",
"GV = GridSearchCV(reg, param, cv=3)\n",
"GV.fit(train_data, train_target)"
]
},
{
"cell_type": "code",
"execution_count": 90,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"LinearRegression(copy_X=True, fit_intercept=True, n_jobs=0, normalize=False)"
]
},
"execution_count": 90,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"GV.best_estimator_"
]
},
{
"cell_type": "code",
"execution_count": 91,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.060939595437028"
]
},
"execution_count": 91,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_absolute_error(GV.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": 92,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n"
]
},
{
"data": {
"text/plain": [
"GridSearchCV(cv=3, error_score='raise-deprecating',\n",
" estimator=SVR(C=1.0, cache_size=200, coef0=0.0, degree=3, epsilon=0.1,\n",
" gamma='auto_deprecated', kernel='rbf', max_iter=-1, shrinking=True,\n",
" tol=0.001, verbose=False),\n",
" fit_params=None, iid='warn', n_jobs=None,\n",
" param_grid={'degree': range(1, 10)}, pre_dispatch='2*n_jobs',\n",
" refit=True, return_train_score='warn', scoring=None, verbose=0)"
]
},
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reg = SVR( )\n",
"param = {'degree':range(1,10)}\n",
"GV = GridSearchCV(reg, param, cv=3)\n",
"GV.fit(train_data, train_target)"
]
},
{
"cell_type": "code",
"execution_count": 93,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"SVR(C=1.0, cache_size=200, coef0=0.0, degree=1, epsilon=0.1,\n",
" gamma='auto_deprecated', kernel='rbf', max_iter=-1, shrinking=True,\n",
" tol=0.001, verbose=False)"
]
},
"execution_count": 93,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"GV.best_estimator_"
]
},
{
"cell_type": "code",
"execution_count": 94,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.9596221674067658"
]
},
"execution_count": 94,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_absolute_error(GV.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": 95,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\model_selection\\_search.py:841: DeprecationWarning: The default of the `iid` parameter will change from True to False in version 0.22 and will be removed in 0.24. This will change numeric results when test-set sizes are unequal.\n",
" DeprecationWarning)\n"
]
},
{
"data": {
"text/plain": [
"GridSearchCV(cv=3, error_score='raise-deprecating',\n",
" estimator=DecisionTreeRegressor(criterion='mse', max_depth=None, max_features=None,\n",
" max_leaf_nodes=None, min_impurity_decrease=0.0,\n",
" min_impurity_split=None, min_samples_leaf=1,\n",
" min_samples_split=2, min_weight_fraction_leaf=0.0,\n",
" presort=False, random_state=None, splitter='best'),\n",
" fit_params=None, iid='warn', n_jobs=None,\n",
" param_grid={'max_depth': range(1, 10)}, pre_dispatch='2*n_jobs',\n",
" refit=True, return_train_score='warn', scoring=None, verbose=0)"
]
},
"execution_count": 95,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reg = DecisionTreeRegressor( )\n",
"param = {'max_depth':range(1,10)}\n",
"GV = GridSearchCV(reg, param, cv=3)\n",
"GV.fit(train_data, train_target)"
]
},
{
"cell_type": "code",
"execution_count": 96,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DecisionTreeRegressor(criterion='mse', max_depth=4, max_features=None,\n",
" max_leaf_nodes=None, min_impurity_decrease=0.0,\n",
" min_impurity_split=None, min_samples_leaf=1,\n",
" min_samples_split=2, min_weight_fraction_leaf=0.0,\n",
" presort=False, random_state=None, splitter='best')"
]
},
"execution_count": 96,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"GV.best_estimator_"
]
},
{
"cell_type": "code",
"execution_count": 97,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.860927072772834"
]
},
"execution_count": 97,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_absolute_error(GV.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": 98,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.060939595437028"
]
},
"execution_count": 98,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reg = LinearRegression().fit(train_data, train_target)\n",
"reg.fit(train_data, train_target)\n",
"mean_absolute_error(reg.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": 99,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"C:\\Users\\Sim\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n"
]
},
{
"data": {
"text/plain": [
"3.9596221674067658"
]
},
"execution_count": 99,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reg = SVR(degree = 1).fit(train_data, train_target)\n",
"reg.fit(train_data, train_target)\n",
"mean_absolute_error(reg.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": 100,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.082237776252947"
]
},
"execution_count": 100,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reg = DecisionTreeRegressor(max_depth=3)\n",
"reg.fit(train_data, train_target)\n",
"mean_absolute_error(reg.predict(test_data), test_target)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"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.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}