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.
1350 lines
1.8 MiB
1350 lines
1.8 MiB
2 years ago
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Setup\n",
|
||
|
"\n",
|
||
|
"`TRAINING_RANGE` und `TEST_RANGE` müssen je nach Länge des Datensatzes angepasst werden.\n",
|
||
|
"\n",
|
||
|
"**Keine Anpassung erforderlich** (Siehe Datensatz herunterladen)\n",
|
||
|
"- 30% Training-Daten (0-30%)\n",
|
||
|
"- 70% Test-Daten (30%-100%)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"311"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"INPUT_FILE = 'data.csv'\n",
|
||
|
"TARGET_COLUMN = 'flt_obd_speed'\n",
|
||
|
"# Still contains positional information and acceleration; however we currently train\n",
|
||
|
"# sample by sample without knowledge of previous or other data, so it should not be\n",
|
||
|
"# possible for the Regressor to simply \"calculate\" the speed.\n",
|
||
|
"EXCLUDED_COLUMNS = ('flt_gps_speed', 'flt_obd_engine_load', 'flt_obd_engine_rpm',\n",
|
||
|
" 'flt_obd_maf', 'flt_obd_accelerator_pedal','flt_time','flt_time_system_clock',\n",
|
||
|
" 'flt_time_utc','flt_ax','flt_ay','flt_az','flt_gx','flt_gy','flt_gz','flt_compass',\n",
|
||
|
" 'flt_number_of_satelites','flt_accuracy','flt_gps_bearing','flt_calc_dist_gps',\n",
|
||
|
" 'flt_calc_dist_vt','flt_calc_ax_vt','flt_timeIP',\n",
|
||
|
" 'weat_latitude','weat_longitude','weat_distanceIP','weat_timeIP','weat_join_idx',\n",
|
||
|
" 'hAccel_1','hAccel_2','hAccel_3','flt_mAccel_1','flt_mAccel_2','flt_mAccel_3',\n",
|
||
|
" 'flt_mGier_1','flt_mGier_2','flt_mGier_3','rot_Accel_1','rot_Accel_2','rot_Accel_3',\n",
|
||
|
" 'rot_Gier_1','rot_Gier_2','rot_Gier_3','rot_Accel_flt_1','rot_Accel_flt_2','rot_Accel_flt_3',\n",
|
||
|
" 'rot_Gier_flt_1','rot_Gier_flt_2','rot_Gier_flt_3'\n",
|
||
|
" )\n",
|
||
|
"# See explanation below the feature importance plot\n",
|
||
|
"OVERFITTING_COLUMNS = ('weat_temperature', 'weat_humidity', 'join_idx', 'weat_windBearing', 'weat_windSpeed',\n",
|
||
|
" 'latitude', 'longitude', 'flt_latitude', 'flt_longitude',\n",
|
||
|
" 'ors_percentage_cumsum', 'flt_obd_air_temperature',\n",
|
||
|
" 'mb_step_weight')\n",
|
||
|
"# Since there are a lot of fields containing those\n",
|
||
|
"# Note: This breaks the map plotting\n",
|
||
|
"OVERFITTING_SUBWORDS = ('distance', 'remainDistance', 'remainDistanze', 'cumsumDistance', 'segDistance', 'time', 'remainTime')\n",
|
||
|
"\n",
|
||
|
"from runsql import runsql\n",
|
||
|
"DATA_COLUMNS = [c['Field']\n",
|
||
|
" for c in runsql('show columns from computeddata')\n",
|
||
|
" if c['Type'] == 'double'\n",
|
||
|
" and c['Field'] != TARGET_COLUMN\n",
|
||
|
" and c['Field'] not in EXCLUDED_COLUMNS\n",
|
||
|
" and c['Field'] not in OVERFITTING_COLUMNS\n",
|
||
|
" and not any([w in c['Field'] for w in OVERFITTING_SUBWORDS])]\n",
|
||
|
"len(DATA_COLUMNS)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Datensatz herunterladen\n",
|
||
|
"\n",
|
||
|
"`SETUP_ID` anpassen, Rest läuft automatisch.\n",
|
||
|
"\n",
|
||
|
"Einige Datensätze besitzen keinen Eintrag für `flt_obd_speed`. Für eine Liste der Datensätze *mit* diesem Wert kann beispielsweise folgende SQL-Abfrage verwendet werden (Achtung, braucht (prinzipbedingt) sehr lange!):\n",
|
||
|
"\n",
|
||
|
"```sql\n",
|
||
|
"select setup_id s, count(*) n\n",
|
||
|
"from computeddata\n",
|
||
|
"group by s\n",
|
||
|
"having not exists (\n",
|
||
|
" select *\n",
|
||
|
" from computeddata\n",
|
||
|
" where setup_id = s\n",
|
||
|
" and flt_obd_speed is null)\n",
|
||
|
"order by n asc\n",
|
||
|
"```"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"SETUP_ID = 868\n",
|
||
|
"import csv\n",
|
||
|
"from runsql import runsql\n",
|
||
|
"reader = runsql('select * from computeddata where setup_id = {} order by distance asc'.format(SETUP_ID))\n",
|
||
|
"reader_data = list(reader) # list(...) so that following cells can be repeated"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import math\n",
|
||
|
"data = []\n",
|
||
|
"target = []\n",
|
||
|
"for row in reader_data:\n",
|
||
|
" data += [[float(row[c]) if row[c] != '' else math.nan for c in DATA_COLUMNS]]\n",
|
||
|
" target += [float(row[TARGET_COLUMN])] # Errors if NaN in TARGET_COLUMN"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"tr_st = 0\n",
|
||
|
"tr_ed = math.floor(len(data)*0.3)\n",
|
||
|
"TRAINING_RANGE = (tr_st, tr_ed)\n",
|
||
|
"TEST_RANGE = (tr_ed, len(data)) # TEST_RANGE = (len(data)-tr_ed, len(data))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Leere Zellen füllen\n",
|
||
|
"\n",
|
||
|
"Da nicht alle Datensätze alle Spalten haben – gäbe sicherlich bessere Strategien, aber das funktioniert erstaunlich gut (wahrscheinlich sind die \"wichtigen\" Spalten immer vorhanden)."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"(7228, 311)"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"from sklearn.impute import SimpleImputer\n",
|
||
|
"imp = SimpleImputer(strategy='constant', fill_value=0) # Other strategies remove fully null columns\n",
|
||
|
"data = imp.fit_transform(data)\n",
|
||
|
"import numpy as np\n",
|
||
|
"np.shape(data)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Analyze INPUT DATA\n",
|
||
|
"Eingangsdaten analysieren"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {
|
||
|
"scrolled": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"ename": "KeyError",
|
||
|
"evalue": "'latitude'",
|
||
|
"output_type": "error",
|
||
|
"traceback": [
|
||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
|
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
|
||
|
"\u001b[0;32m<ipython-input-6-fda9f06cb23c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mastropy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtable\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mTable\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mTable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnames\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mDATA_COLUMNS\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mlat\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'latitude'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mlng\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'longitude'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;31m# Subsampling ... use points every 50m for plotting\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m~/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/astropy/table/table.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 1221\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__getitem__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1222\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1223\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1224\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minteger\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1225\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m~/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/astropy/table/table.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 105\u001b[0m \"\"\"\n\u001b[1;32m 106\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 107\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mOrderedDict\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getitem__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 108\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minteger\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 109\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;31mKeyError\u001b[0m: 'latitude'"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Convert to Table\n",
|
||
|
"import sys\n",
|
||
|
"from astropy.table import Table\n",
|
||
|
"t = Table(data, names=DATA_COLUMNS)\n",
|
||
|
"lat = t['latitude']\n",
|
||
|
"lng = t['longitude']\n",
|
||
|
"# Subsampling ... use points every 50m for plotting\n",
|
||
|
"lat = lat[::10]\n",
|
||
|
"lng = lng[::10]\n",
|
||
|
"# determine range to print based on min, max lat and lon of the data\n",
|
||
|
"margin = 0 # buffer to add to the range\n",
|
||
|
"lat_min = min(lat) - margin\n",
|
||
|
"lat_max = max(lat) + margin\n",
|
||
|
"lon_min = min(lng) - margin\n",
|
||
|
"lon_max = max(lng) + margin\n",
|
||
|
"t"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"ename": "NameError",
|
||
|
"evalue": "name 'lon_min' is not defined",
|
||
|
"output_type": "error",
|
||
|
"traceback": [
|
||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
|
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
||
|
"\u001b[0;32m<ipython-input-10-d80dd05874af>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;31m# Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0moriginShift\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpi\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;36m6378137\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m2.0\u001b[0m\u001b[0;34m;\u001b[0m \u001b[0;31m# 20037508.342789244\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mxExtent_min\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlon_min\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0moriginShift\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m180\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0myExtent_min\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlog\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtan\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m90\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mlat_min\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpi\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m360\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpi\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m180\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0myExtent_min\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0myExtent_min\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0moriginShift\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m180\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;31mNameError\u001b[0m: name 'lon_min' is not defined"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Calculation ZOOM LEVEL\n",
|
||
|
"width = 640\n",
|
||
|
"height = 640\n",
|
||
|
"tileSize= 256*4\n",
|
||
|
"\n",
|
||
|
"# Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913\"\n",
|
||
|
"originShift = 2 * math.pi * 6378137/2.0; # 20037508.342789244\n",
|
||
|
"xExtent_min = lon_min * originShift / 180;\n",
|
||
|
"yExtent_min = math.log(math.tan((90 + lat_min) * math.pi / 360 )) / (math.pi / 180);\n",
|
||
|
"yExtent_min = yExtent_min * originShift / 180;\n",
|
||
|
"xExtent_max = lon_max * originShift / 180;\n",
|
||
|
"yExtent_max = math.log(math.tan((90 + lat_max) * math.pi / 360 )) / (math.pi / 180);\n",
|
||
|
"yExtent_max = yExtent_max * originShift / 180;\n",
|
||
|
"\n",
|
||
|
"minResX = (xExtent_max-xExtent_min)/width;\n",
|
||
|
"minResY = (yExtent_max-yExtent_min)/height;\n",
|
||
|
"minRes = max([minResX, minResY]);\n",
|
||
|
"initialResolution = 2 * math.pi * 6378137 / tileSize; # 156543.03392804062 for tileSize 256 pixels\n",
|
||
|
"zoomlevel = math.floor(math.log2(initialResolution/minRes));\n",
|
||
|
"\n",
|
||
|
"# Enforce valid zoom levels\n",
|
||
|
"if zoomlevel < 0:\n",
|
||
|
" zoomlevel = 0\n",
|
||
|
"if zoomlevel > 19: \n",
|
||
|
" zoomlevel = 19"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"ename": "NameError",
|
||
|
"evalue": "name 'lat' is not defined",
|
||
|
"output_type": "error",
|
||
|
"traceback": [
|
||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
|
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
||
|
"\u001b[0;32m<ipython-input-11-546f749e9267>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 9\u001b[0m data_p = [\n\u001b[1;32m 10\u001b[0m go.Scattermapbox(\n\u001b[0;32m---> 11\u001b[0;31m \u001b[0mlat\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlat\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 12\u001b[0m \u001b[0mlon\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlng\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'markers'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;31mNameError\u001b[0m: name 'lat' is not defined"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Analyze Data\n",
|
||
|
"import plotly\n",
|
||
|
"import plotly.graph_objs as go\n",
|
||
|
"import plotly.plotly as py\n",
|
||
|
"\n",
|
||
|
"plotly.tools.set_credentials_file(username='ziegmann', api_key='yGii8dk78Sjz7jzzad1n')\n",
|
||
|
"mapbox_access_token = 'pk.eyJ1Ijoiam9oYW5ubmVzLXppZWdtYW5uIiwiYSI6ImNqbDJmamo5bDFxNjQzcWxtd2IzejNhcXoifQ.iVXGH-jpe2FH3f52MM9yHQ'\n",
|
||
|
"\n",
|
||
|
"data_p = [\n",
|
||
|
" go.Scattermapbox(\n",
|
||
|
" lat=lat,\n",
|
||
|
" lon=lng,\n",
|
||
|
" mode='markers',\n",
|
||
|
" marker=dict(size=6))\n",
|
||
|
"]\n",
|
||
|
"\n",
|
||
|
"layout = go.Layout(\n",
|
||
|
" title='OBD-II GPS Logging',\n",
|
||
|
" autosize=True,\n",
|
||
|
" hovermode='closest',\n",
|
||
|
" mapbox=dict(\n",
|
||
|
" accesstoken=mapbox_access_token,\n",
|
||
|
" bearing=0,\n",
|
||
|
" center=dict(\n",
|
||
|
" lon=(lon_max-lon_min)/2+lon_min,\n",
|
||
|
" lat=(lat_max-lat_min)/2+lat_min,\n",
|
||
|
" ),\n",
|
||
|
" style='dark',\n",
|
||
|
" pitch=0,\n",
|
||
|
" zoom=zoomlevel\n",
|
||
|
" ),\n",
|
||
|
")\n",
|
||
|
"\n",
|
||
|
"fig = dict(data=data_p, layout=layout)\n",
|
||
|
"#plotly.offline.plot(fig, filename='Mapbox.html')\n",
|
||
|
"py.iplot(fig, filename='Mapbox.html')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 12,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"ename": "KeyError",
|
||
|
"evalue": "'distance'",
|
||
|
"output_type": "error",
|
||
|
"traceback": [
|
||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
|
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
|
||
|
"\u001b[0;32m<ipython-input-12-6fad4a6b6b96>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpyplot\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplot\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mtemp_d\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'distance'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mxaxis\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtemp_d\u001b[0m \u001b[0;31m# range(int(temp_d[0]), int(temp_d[-1]))\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mplot\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfigure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfigsize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m15\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mplot\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maxvline\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtemp_d\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mTRAINING_RANGE\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m~/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/astropy/table/table.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 1221\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__getitem__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1222\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1223\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1224\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minteger\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1225\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m~/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/astropy/table/table.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 105\u001b[0m \"\"\"\n\u001b[1;32m 106\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 107\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mOrderedDict\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getitem__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 108\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minteger\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 109\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;31mKeyError\u001b[0m: 'distance'"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import matplotlib.pyplot as plot\n",
|
||
|
"temp_d=t['distance']\n",
|
||
|
"xaxis = temp_d # range(int(temp_d[0]), int(temp_d[-1]))\n",
|
||
|
"plot.figure(figsize=(15,10))\n",
|
||
|
"plot.axvline(x=temp_d[TRAINING_RANGE[0]])\n",
|
||
|
"plot.axvline(x=temp_d[TEST_RANGE[0]])\n",
|
||
|
"plot.plot(temp_d[TEST_RANGE[0]:TEST_RANGE[1]], target[TEST_RANGE[0]:TEST_RANGE[1]], 'b',\n",
|
||
|
" xaxis, t['hr_traficSpeed']*3.6, 'r',\n",
|
||
|
" xaxis, t['hr_SpeedLimit'],\n",
|
||
|
" )\n",
|
||
|
"plot.legend(['Training','Test','OBD Speed','HERE Traffic Speed', 'HERE Speed Limint'])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Hyperparametersuche\n",
|
||
|
"\n",
|
||
|
"Utility-Methode; wurde zum Testen verschiedener Ansätze verwendet (könnte man jetzt vermutlich inlinen)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 13,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def gridsearch(base, params, n_jobs = None, scoring = 'neg_mean_squared_error', cv = 5):\n",
|
||
|
" if n_jobs == None:\n",
|
||
|
" import os\n",
|
||
|
" n_jobs = os.cpu_count()\n",
|
||
|
" from sklearn.model_selection import GridSearchCV\n",
|
||
|
" return GridSearchCV(base, params, n_jobs = n_jobs, scoring = scoring, cv = cv)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Training\n",
|
||
|
"\n",
|
||
|
"Bei großen Datensätzen kann es zur Fehlerausgabe \"UserWarning: A worker stopped while some jobs were given to the executor. This can be caused by a too short worker timeout or by a memory leak.\" kommen. Scheint vereinzelt am Ergebnis aber nicht viel zu ändern.\n",
|
||
|
"\n",
|
||
|
"Es werden alle gegebenen Parameterkombinationen mittels Cross-Validation getestet; die besten für die Vorhersage verwendet und dann auch ausgegeben."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 14,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/model_selection/_search.py:841: DeprecationWarning:\n",
|
||
|
"\n",
|
||
|
"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",
|
||
|
"\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"{'max_depth': 20, 'max_features': 'auto', 'n_estimators': 40}"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 14,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"from sklearn.ensemble import ExtraTreesRegressor\n",
|
||
|
"clf = gridsearch(ExtraTreesRegressor(),\n",
|
||
|
" [{'n_estimators': range(10, 151, 10), # range(50, 151, 25) woher kommt dieser Range ??? bzw. wie hast du diesen bestimmt\n",
|
||
|
" #'criterion': 'mse', # or mae\n",
|
||
|
" 'max_depth': [None] + list(range(5, 30, 5)), # [None] + list(range(5, 30, 5)) woher kommt die Tiefe???\n",
|
||
|
" 'max_features': ['auto', 'sqrt', 'log2']}])\n",
|
||
|
"clf.fit(data[TRAINING_RANGE[0]:TRAINING_RANGE[1]], target[TRAINING_RANGE[0]:TRAINING_RANGE[1]])\n",
|
||
|
"\n",
|
||
|
"clf.best_params_"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Testen und Plotten\n",
|
||
|
"\n",
|
||
|
"Wenn mir anderem Datensatz getestet werden soll:\n",
|
||
|
"- Neuen Datensatz herunterladen und einlesen\n",
|
||
|
"- Eventuell `TEST_RANGE` anpassen\n",
|
||
|
"- Untere Zelle ausführen"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 15,
|
||
|
"metadata": {
|
||
|
"scrolled": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.legend.Legend at 0x7f5755c555d0>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 15,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA3AAAAJCCAYAAACBLyXFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzs3Xd8VFX6x/HPTYNAICQh9B5pQSBAQBFREEVcBBuKZRU79hUXFX+rC+oWdq0rorLuKhYEFF3sitgQC01CJ4QuNRBaQku7vz9O7swkmZBJmcwk+b5fr3ndmTu3nCmB+8zznHMs27YRERERERGR4BcS6AaIiIiIiIiIbxTAiYiIiIiIVBMK4ERERERERKoJBXAiIiIiIiLVhAI4ERERERGRakIBnIiIiIiISDWhAE5ERERERKSaUAAnIiIiIiJSTSiAExERERERqSbCAt0AgMaNG9vt2rULdDMK2bzvKAAd4usHuCUiAvqbFBERkZpt2bJl+23bji9tu6AI4Nq1a8fSpUsD3YxCRk/7GYDZY/sHuCUiAvqbFBERkZrNsqxtvmynEkoREREREZFqQgGciIiIiIhINaEATkREREREpJoIij5wIiIiIiLBJCcnhx07dnDixIlAN0VqmLp169KqVSvCw8PLtb8COBERERGRInbs2EGDBg1o164dlmUFujlSQ9i2TUZGBjt27KB9+/blOoZKKEVEREREijhx4gRxcXEK3qRSWZZFXFxchTK7CuBERERERLxQ8Cb+UNHvlQI4ERERERGRakIBnIiIiIhIkMnIyCApKYmkpCSaNWtGy5YtXY+zs7N9OsZNN91EamrqKbeZOnUqM2bMqIwmSxXRICYiIiIiIkEmLi6OlJQUACZNmkRUVBTjx48vtI1t29i2TUiI95zM66+/Xup57r777oo3VqqUMnAiIiIiItXExo0bSUxM5LrrrqNbt27s3r2b22+/neTkZLp168YTTzzh2vbss88mJSWF3NxcGjVqxIQJE+jZsyf9+/cnPT0dgEcffZTnn3/etf2ECRPo168fnTt35qeffgLg6NGjXHHFFSQmJjJq1CiSk5NdwaVUPWXgRERERERO4fGP17B215FKPWZii4ZMHNGtXPuuX7+eN998k+TkZAAmT55MbGwsubm5DB48mFGjRpGYmFhon8OHD3PuuecyefJkHnjgAV577TUmTJhQ7Ni2bbN48WI++ugjnnjiCb744gumTJlCs2bNeP/991mxYgW9e/cuV7ulcigDJyIiIiJSjSQkJLiCN4CZM2fSu3dvevfuzbp161i7dm2xfSIjI7nooosA6NOnD1u3bvV67Msvv7zYNgsXLuTqq68GoGfPnnTrVr7AUyqHMnAiIiIiIqdQ3kyZv9SvX991Py0tjX/9618sXryYRo0a8fvf/97rHGMRERGu+6GhoeTm5no9dp06dUrdRgJLGTgRERERkWrqyJEjNGjQgIYNG7J7926+/PLLSj/HgAEDePfddwFYtWqV1wyfVB1l4EREREREqqnevXuTmJhIly5daNu2LQMGDKj0c9x7773ccMMNJCYmum7R0dGVfh7xjWXbdqDbQHJysr106dJAN6OQ0dN+BmD22P4BbomIgP4mRUSkaq1bt46uXbsGuhlBITc3l9zcXOrWrUtaWhpDhw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iIi4KYATERHAZNyioyE+3jzet8/MBderF7RrF9CmiYjUOhkZGSQlJZGUlESzZs1o2bKl63F2djZz587FsizWr1/v2mfr1q1ERkaSlJREYmIiN9xwAzk5Oa7nFy9ezKBBg+jYsSO9e/dm+PDhrFq1CjBTFXieIykpidmzZ7vuR0VF0blzZ5KSkrjhhhuKtXfNmjWcd955dO7cmY4dO/Lkk09i2zYA06dPJz4+nqSkJLp168aoUaM4duxYsfN27NiRyy+/nLVr13p9T3755RfOOOMMkpKS6Nq1a7HpFSrb9OnTueeee/x6jvJQACciIoA7gKtbFxo2NIOa7NplnrNtcxMRkaoRFxdHSkoKKSkp3HHHHYwbN871OCIigpkzZ3L22Wczc+bMQvslJCSQkpLCqlWr2LFjB++++y4Ae/fu5aqrruJvf/sbaWlp/PrrrzzyyCNs2rTJta/nOVJSUhg9erTrfnJyMjNmzCAlJYU333yz0DmPHz/OyJEjmTBhAqmpqaxYsYKffvqJl156ybWNc6w1a9YQERHB7Nmzi503LS2N0aNHc95557Fv375i78mYMWP497//TUpKCqtXr66189spgBMREcAEcA0bmvtNm5pBTdascT/vTDMgIiKBlZWVxcKFC/nvf//LrFmzvG4TGhpKv3792LlzJwAvvvgiY8aM4ayzznJtc/bZZ3PppZdWuD3vvPMOAwYMYOjQoQDUq1ePF198kcmTJxfbNjc3l6NHjxITE+P1WKNHj2bo0KG88847xZ5LT0+nefPmrteXmJgImCze9ddfT//+/enYsSOvvvqqa5+nnnqKvn370qNHDyZOnOha//bbb9OvXz+SkpIYO3YseXl5ALz++ut06tSJfv368eOPP5bzHfGvsEA3QEREgoPTBw7MaJS//QaPP+5+/oEHwMv/pyIiNd7995v+wJUpKQmef758+3744YcMGzaMTp06ERcXx7Jly+jTp0+hbU6cOMGiRYv417/+BZgSxzFjxpzyuM899xxvv/02ADExMXz77bc+tWfNmjXFzp+QkEBWVhZHCoY0nj17NgsXLmT37t106tSJESNGlHi83r17FyoNdYwbN47OnTszaNAghg0bxpgxY6hbty4AK1eu5JdffuHo0aP06tWL4cOHs3r1atLS0li8eDG2bTNy5EgWLFhAfHw8s2fP5scffyQ8PJy77rqLGTNmcMEFFzBx4kSWLVtGdHQ0gwcPplevXj69B1VJGTgREeHkSXNzAriWLeG
|
||
|
"text/plain": [
|
||
|
"<Figure size 1080x720 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"xaxis = range(0, TEST_RANGE[1])\n",
|
||
|
"plot.figure(figsize=(15,10))\n",
|
||
|
"plot.axvline(x=TRAINING_RANGE[0])\n",
|
||
|
"plot.axvline(x=TRAINING_RANGE[1])\n",
|
||
|
"plot.plot(xaxis, target, 'b', xaxis, clf.predict(data), 'r')\n",
|
||
|
"plot.legend(['Training','Test','TARGET OBD Speed','PREDICTED OBD Speed'])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Anscheinend wird immer die höchste Geschwindigkeit vorrausgesagt, die der Regressor je gesehen hat. Wird er beispielsweise mit einer Landstraßenfahrt trainiert, ist auch auf der Autobahn bei 100 km/h Schluss."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 16,
|
||
|
"metadata": {
|
||
|
"scrolled": true
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<BarContainer object of 311 artists>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 16,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA/UAABClCAYAAAB6A0FdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cG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IklbQgKffS5omhvrx3VJVywGS3ABcWlWVZDkwt/37U4CqujDJnRO0d1SS/dr1U4B5VbUkyY+S7Ar8ANgaWAy8HfhqVd0P3J/kn4e1swz4fJKvAF8ZVv7Vqvo18Oskl9EF+d2BvXk4mM+iC/nb0wX3a5IAbAT8J7ALMFBVv2jPfS7wjIk+qCSzgOcDX2jtAcxsP3cD9m3X5wAfmag9SZIkSdLEDPXje2DY9W+H/f5bus/uwck2lGQBsBewW1Xdl2QA2LD9+Z+A1wI3Aee3Lw7Ga+5lwJ7AK4Bjk2zXykfObhfd7PyHquq0EeM5Ejirqt4zonxfVs56wF1VteNK3i9JkiRJWkHuqX9kLqdbkk+SfYDHjlN3NnBnC/Rb0y2TH3I+8Crg9XQBH7rZ+lck2bDNgr+89bMe8JSqugx4d2t3VrvnVa3+44EFdFsGLgYOa22QZIskTwAuBfZv1yR5XJI/BK4C/qidF7AB3faDCVXVfwO3JHlNay9Jdmh/XkK3lQDgdZNpT5IkSZI0MWfqH5njgUVtaf6/0u2xH8tFwBFJvgfcTBd0AaiqO1v5NlV1dSu7JskFdEvtfw4sp9vjPgM4O8lsuln4j1XVXW1mfxndHvjNgBOq6qfAT5M8C7iy1bkHeENV3ZjkvcAl7YuC3wBva9sBjqPb538XcP0KfB4HAf/Y2t2A7guK7wDvaGM+tn0OE56Ct90Wsxl0b5okSZIkjStVnkc2VZLcCsyvql9OUXu
|
||
|
"text/plain": [
|
||
|
"<Figure size 1080x5598 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plot.figure(figsize = (15, 0.25 * len(DATA_COLUMNS)))\n",
|
||
|
"importances = clf.best_estimator_.feature_importances_\n",
|
||
|
"stddev = np.var([t.feature_importances_ for t in clf.best_estimator_.estimators_], axis = 0)\n",
|
||
|
"sorted_indices = np.argsort(importances)\n",
|
||
|
"plot.barh(np.array(DATA_COLUMNS)[sorted_indices], importances[sorted_indices], xerr = stddev[sorted_indices])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Einige der Top-Features sprachen für starkes Overfitting:\n",
|
||
|
"- Temperatur und Luftfeuchtigkeit (`weat_temperature`, `weat_humidity`) bewegen kleinem Rahmen, und sollten auf das Fahrverhalten nur bedingten Einfluss haben (wenn überhaupt, nur auf längere Sicht gesehen; z.B. langsameres Fahren bei schlechtem Wetter).\n",
|
||
|
"- `join_idx` macht keinen Sinn.\n",
|
||
|
"- Position (Breiten- und Längengrad: `flt_latitude`, `latitude`, `longitude`, `flt_longitude`) funktionieren nur auf einer spezifischen Strecke. Das Lernen von Eigenheiten dieser Strecke ist nicht Aufgabe des Regressors; das sollte höchstens in anderen Datenquellen gespeichert und dann zur Berechnung hergezogen werden.\n",
|
||
|
"- Zeit und Entfernung (`hr_remainDistance`, `tt_calc_distance`, `ei_distance_lldist`, `hr_distance_lldist`, `gh_distance_lldist`, `time` etc.) sind schlecht auf andere Fahrten übertragbar; würde ich dieselbe Strecke von einem anderen Ausgangspunkt aus fahren, wäre die gesamte Vorhersage verschoben\n",
|
||
|
"- Windrichtung (`weat_windBearing`) hätte durchaus einen Einfluss (Rücken-/Gegenwind), allerdings nur, wenn die aktuelle Fahrtrichtung auch verwendet wird\n",
|
||
|
"\n",
|
||
|
"Diese Features wurden daher ausgeschlossen, was zu einer merklichen Verbesserung der Prädiktion führt (ist nun besser als HERE Maps in nahezu allen verwendeten Kriterien).\n",
|
||
|
"\n",
|
||
|
"Interessanterweise scheinen die Bäume allerdings vor allem eine Aggregation verschiedener Quellen für die Durchschnittsgeschwindigkeit zu sein …"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Gütekriterium - Prädiktion\n",
|
||
|
"\n",
|
||
|
"Berechung des Gütekritierums\n",
|
||
|
"- Root-mean-square deviation RMSE\n",
|
||
|
"- NRMSE Normalized root-mean-square deviation\n",
|
||
|
"- Mean absolute error MAE\n",
|
||
|
"- Mean absolute percentage error MAP\n",
|
||
|
"- Symmetric mean absolute percentage error\n",
|
||
|
"- https://en.wikipedia.org/wiki/Least_absolute_deviations\n",
|
||
|
"- https://en.wikipedia.org/wiki/Mean_signed_deviation\n",
|
||
|
"- Pearson Correlation Coefficient\n",
|
||
|
"- Accuracy (Interval of given size; absolute and relative)\n",
|
||
|
"- Median Absolute Deviation\n",
|
||
|
"\n",
|
||
|
"BITTE weitere Kriterien ergänzen\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 17,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"RMSE = 12.96 km/h\n",
|
||
|
"NRMSE = 43.53 %\n",
|
||
|
"MAE = 9.77 km/h\n",
|
||
|
"MAP = 11.39 %\n",
|
||
|
"SMAPE = 11.60 %\n",
|
||
|
"MSD = 6.06 km/h\n",
|
||
|
"CORR = 0.87\n",
|
||
|
"ACC_A = 59.66 %\n",
|
||
|
"ACC_R = 53.50 %\n",
|
||
|
"MAD = 7.29 km/h\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"ta = target[TEST_RANGE[0]:TEST_RANGE[1]]\n",
|
||
|
"pr = clf.predict(data[TEST_RANGE[0]:TEST_RANGE[1]])\n",
|
||
|
"RMSE = math.sqrt(sum((ta-pr)**2)/len(ta))\n",
|
||
|
"print(\"RMSE = %.2f km/h\" %RMSE)\n",
|
||
|
"NRMSE = 1-math.sqrt(sum((ta-pr)**2))/math.sqrt(sum( (ta-np.mean(ta) )**2 ))\n",
|
||
|
"print(\"NRMSE = %.2f %%\" %(NRMSE*100))\n",
|
||
|
"MAE = sum(((ta-pr)**2)**(1/2))/len(ta)\n",
|
||
|
"print(\"MAE = %.2f km/h\" %MAE)\n",
|
||
|
"with np.errstate(divide = 'ignore'): map_elements = np.abs((ta - pr) / ta)\n",
|
||
|
"map_elements[map_elements == np.inf] = 0\n",
|
||
|
"MAP = np.sum(map_elements) / len(ta)\n",
|
||
|
"print(\"MAP = %.2f %%\" % (MAP*100))\n",
|
||
|
"SMAPE = np.sum(np.abs(ta - pr) / ((ta + pr) / 2)) / len(ta)\n",
|
||
|
"print(\"SMAPE = %.2f %%\" % (SMAPE*100))\n",
|
||
|
"MSD = np.sum(ta - pr) / len(ta)\n",
|
||
|
"print(\"MSD = %.2f km/h\" % MSD)\n",
|
||
|
"CORR = np.corrcoef(ta, pr)[1][0]\n",
|
||
|
"print(\"CORR = %.2f\" % CORR)\n",
|
||
|
"ACC_A_THRESHOLD = 10\n",
|
||
|
"ACC_A = (np.abs(ta - pr) < ACC_A_THRESHOLD).sum() / len(ta)\n",
|
||
|
"print(\"ACC_A = %.2f %%\" % (ACC_A*100))\n",
|
||
|
"ACC_R_THRESHOLD = 0.1\n",
|
||
|
"ACC_R = (np.abs(ta / pr - 1) < ACC_R_THRESHOLD).sum() / len(ta)\n",
|
||
|
"print(\"ACC_R = %.2f %%\" % (ACC_R*100))\n",
|
||
|
"MAD = np.median(np.abs(ta - pr))\n",
|
||
|
"print(\"MAD = %.2f km/h\" % MAD)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Vergleich mit HERE Maps Trafic Speed\n",
|
||
|
"Kann zum Vergleich sehr gut herangezogen werden ;)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 18,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"RMSE = 16.82 km/h\n",
|
||
|
"NRMSE = 26.73 %\n",
|
||
|
"MAE = 14.06 km/h\n",
|
||
|
"MAP = 15.87 %\n",
|
||
|
"SMAPE = 16.62 %\n",
|
||
|
"MSD = 9.82 km/h\n",
|
||
|
"CORR = 0.81\n",
|
||
|
"ACC_A = 40.18 %\n",
|
||
|
"ACC_R = 32.00 %\n",
|
||
|
"MAD = 12.84 km/h\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"ta = target[TEST_RANGE[0]:TEST_RANGE[1]]\n",
|
||
|
"pr = t['hr_traficSpeed']\n",
|
||
|
"pr = pr[TEST_RANGE[0]:TEST_RANGE[1]] * 3.6\n",
|
||
|
"RMSE = math.sqrt(sum((ta-pr)**2)/len(ta))\n",
|
||
|
"print(\"RMSE = %.2f km/h\" %RMSE)\n",
|
||
|
"NRMSE = 1-math.sqrt(sum((ta-pr)**2))/math.sqrt(sum( (ta-np.mean(ta) )**2 ))\n",
|
||
|
"print(\"NRMSE = %.2f %%\" %(NRMSE*100))\n",
|
||
|
"MAE = sum(((ta-pr)**2)**(1/2))/len(ta)\n",
|
||
|
"print(\"MAE = %.2f km/h\" %MAE)\n",
|
||
|
"with np.errstate(divide = 'ignore'): map_elements = np.abs((ta - pr) / ta)\n",
|
||
|
"map_elements[map_elements == np.inf] = 0\n",
|
||
|
"MAP = np.sum(map_elements) / len(ta)\n",
|
||
|
"print(\"MAP = %.2f %%\" % (MAP*100))\n",
|
||
|
"SMAPE = np.sum(np.abs(ta - pr) / ((ta + pr) / 2)) / len(ta)\n",
|
||
|
"print(\"SMAPE = %.2f %%\" % (SMAPE*100))\n",
|
||
|
"MSD = np.sum(ta - pr) / len(ta)\n",
|
||
|
"print(\"MSD = %.2f km/h\" % MSD)\n",
|
||
|
"CORR = np.corrcoef(ta, pr)[1][0]\n",
|
||
|
"print(\"CORR = %.2f\" % CORR)\n",
|
||
|
"ACC_A_THRESHOLD = 10\n",
|
||
|
"ACC_A = (np.abs(ta - pr) < ACC_A_THRESHOLD).sum() / len(ta)\n",
|
||
|
"print(\"ACC_A = %.2f %%\" % (ACC_A*100))\n",
|
||
|
"ACC_R_THRESHOLD = 0.1\n",
|
||
|
"ACC_R = (np.abs(ta / pr - 1) < ACC_R_THRESHOLD).sum() / len(ta)\n",
|
||
|
"print(\"ACC_R = %.2f %%\" % (ACC_R*100))\n",
|
||
|
"MAD = np.median(np.abs(ta - pr))\n",
|
||
|
"print(\"MAD = %.2f km/h\" % MAD)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Generalisierbarkeit\n",
|
||
|
"\n",
|
||
|
"Nach der abgeschlossenen Fahrt wird mit der ganzen Fahrt trainiert, und anschließend eine andere Fahrt vorhergesagt. Als Parameter werden die gefundenen Parameter der Grid Search beim ersten mal verwendet, wodurch sich der Vorgang erheblich beschleunigt."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 19,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"ExtraTreesRegressor(bootstrap=False, criterion='mse', max_depth=20,\n",
|
||
|
" max_features='auto', max_leaf_nodes=None,\n",
|
||
|
" min_impurity_decrease=0.0, min_impurity_split=None,\n",
|
||
|
" min_samples_leaf=1, min_samples_split=2,\n",
|
||
|
" min_weight_fraction_leaf=0.0, n_estimators=40, n_jobs=None,\n",
|
||
|
" oob_score=False, random_state=None, verbose=0, warm_start=False)"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 19,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"clf2 = ExtraTreesRegressor(n_estimators = clf.best_params_['n_estimators'],\n",
|
||
|
" max_depth = clf.best_params_['max_depth'],\n",
|
||
|
" max_features = clf.best_params_['max_features'])\n",
|
||
|
"clf2.fit(data, target)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 20,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<BarContainer object of 311 artists>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 20,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA/cAABClCAYAAAB+9pFgAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzs3XmUZkV9//H3hx3BDCIYRoyOwigim9CiyOIkIu4KihLB6KA/ccXtoCGRKIsLSgQUSBQI4FEZcUMJRIEQOuAIMj0CwyJoFDQiKBogIEsEvr8/brU0bU9Pz9DMM5d5v86Z0/epp25V3Qf++dyqWzdVhSRJkiRJ6q9VBj0ASZIkSZL00BjuJUmSJEnqOcO9JEmSJEk9Z7iXJEmSJKnnDPeSJEmSJPWc4V6SJEmSpJ4z3EuSJEmS1HOGe0mSJEmSes5wL0mSJElSz6026AFIE9lggw1q1qxZgx6GJEmSJA3EwoULf1tVG061vuFeK6RZs2YxMjIy6GFIkiRJ0kAk+fnS1HdZviRJkiRJPWe4lyRJkiSp5wz3kiRJkiT1nOFekiRJkqSeM9xLkiRJktRzhntJkiRJknrOcC9JkiRJUs8Z7iVJkiRJ6jnDvSRJkiRJPWe4lyRJkiSp5wz3kiRJkiT1nOFekiRJkqSeM9xLkiRJktRzhntJkiRJknrOcC9JkiRJUs8Z7iVJkiRJ6jnDvSRJkiRJPWe4lyRJkiSp5wz3kiRJkiT1nOFekiRJkqSeM9xLkiRJktRzhntJkiRJknrOcC9JkiRJUs8Z7iVJkiRJ6jnDvSRJkiR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jkESXrYXe/jR5IkaZoY7lcQLcQPJMhLkiRJkvrNZfkPoySzkly5jOfunmTzZThvzST/nuSyJHs
|
||
|
"text/plain": [
|
||
|
"<Figure size 1080x5598 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plot.figure(figsize = (15, 0.25 * len(DATA_COLUMNS)))\n",
|
||
|
"importances = clf2.feature_importances_\n",
|
||
|
"stddev = np.var([t.feature_importances_ for t in clf2.estimators_], axis = 0)\n",
|
||
|
"sorted_indices = np.argsort(importances)\n",
|
||
|
"plot.barh(np.array(DATA_COLUMNS)[sorted_indices], importances[sorted_indices], xerr = stddev[sorted_indices])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 21,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"SETUP_ID_2 = 450\n",
|
||
|
"\n",
|
||
|
"reader2 = runsql('select * from computeddata where setup_id = {} order by distance asc'.format(SETUP_ID_2))\n",
|
||
|
"reader_data2 = list(reader2) # list(...) so that following cells can be repeated"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 22,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"data2 = []\n",
|
||
|
"target2 = []\n",
|
||
|
"for row in reader_data2:\n",
|
||
|
" data2 += [[float(row[c]) if row[c] != '' else math.nan for c in DATA_COLUMNS]]\n",
|
||
|
" target2 += [float(row[TARGET_COLUMN]) if row[TARGET_COLUMN] != '' else math.nan]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 23,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"data2 = imp.transform(data2)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 24,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"np.savetxt('imputed-{}.csv'.format(SETUP_ID_2), data2, delimiter=',')\n",
|
||
|
"np.savetxt('target-{}.csv'.format(SETUP_ID_2), target2, delimiter=',')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 23,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.legend.Legend at 0x7f9554dc71d0>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 23,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA3EAAAJCCAYAAABu7U77AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzsnXmYFNXVxt+aYYYZGNZh2GUVEBAYkEUiGNEoGAV3MSYKn2viToJBExfcolGjoqLGJEoIyuK+G4yiiAsIMuwgi6AgMKzD7Gt9fxzuVPU2Xd1d1V3d9f6eZ55bfWu701Vddd97zj1H03UdhBBCCCGEEEKSg7REN4AQQgghhBBCiHUo4gghhBBCCCEkiaCII4QQQgghhJAkgiKOEEIIIYQQQpIIijhCCCGEEEIISSIo4gghhBBCCCEkiaCII4QQQgghhJAkgiKOEEIIIYQQQpIIijhCCCGEEEIISSIaJboBANCmTRu9W7duiW4GIYQQQgghhCSEFStW7Nd1Pc/Ktq4Qcd26dcPy5csT3QxCCCGEEEIISQiapu2wui3dKQkhhBBCCCEkiaCII4QQQgghhJAkgiKOEEIIIYQQQpIIV8yJC0Z1dTV27t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Pe//x3vvfde/TZTpkxBQUEB1q9fjzVr1uCzzz6rX/fII49g1apV2LRpEwYPHoxTTz0VVVVVPueorq7GNddcg3feeQerVq3CypUrccopp0RxZQg
|
||
|
"text/plain": [
|
||
|
"<Figure size 1080x720 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plot.figure(figsize=(15,10))\n",
|
||
|
"xaxis = range(0, len(target2))\n",
|
||
|
"plot.plot(xaxis, target2, 'b', xaxis, clf2.predict(data2), 'r')\n",
|
||
|
"plot.legend(['TARGET OBD Speed','PREDICTED OBD Speed'])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Wie bereits vorher festgestellt, scheint der Regressor mit höheren Geschwindigkeiten nicht vertraut. Trainieren wir also mit diesem Datensatz einen weiteren Regressor, und testen wieder mit einem anderen."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 24,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"ExtraTreesRegressor(bootstrap=False, criterion='mse', max_depth=None,\n",
|
||
|
" max_features='auto', max_leaf_nodes=None,\n",
|
||
|
" min_impurity_decrease=0.0, min_impurity_split=None,\n",
|
||
|
" min_samples_leaf=1, min_samples_split=2,\n",
|
||
|
" min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=None,\n",
|
||
|
" oob_score=False, random_state=None, verbose=0, warm_start=False)"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 24,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"clf3 = ExtraTreesRegressor(n_estimators = clf.best_params_['n_estimators'],\n",
|
||
|
" max_depth = clf.best_params_['max_depth'],\n",
|
||
|
" max_features = clf.best_params_['max_features'])\n",
|
||
|
"clf3.fit(data2, target2)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 25,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<BarContainer object of 311 artists>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 25,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA/UAABClCAYAAAB6A0FdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzs3Xm4XlV99//3hwBh0lAFS0ptoxBQBEE4oshg2iIqasWKUnFgeCpOxemHLVafOtVHLK2iotXID/BSiTiAUqgMIkcwMuQEQgIo+gg4AdZaoDKq8H3+2Ct6PJ4pIcmdzXm/rutcZ591r73W2jv553OvtddOVSFJkiRJkvpng0EPQJIkSZIkrR5DvSRJkiRJPWWolyRJkiSppwz1kiRJkiT1lKFekiRJkqSeMtRLkiRJktRThnpJkiRJknrKUC9JkiRJUk8Z6iVJkiRJ6qkNBz0AaTxbbbVVzZs3b9DDkCRJkqSBWLp06X9V1dZT1TPUa700b948RkZGBj0MSZIkSRqIJD+YTj2X30uSJEmS1FOGekmSJEmSespQL0mSJElSTxnqJUmSJEnqKUO9JEmSJEk9ZaiXJEmSJKmnDPWSJEmSJPWUoV6SJEmSpJ4y1EuSJEmS1FOGekmSJEmSespQL0mSJElSTxnqJUmSJEnqKUO9JEmSJEk9ZaiXJEmSJKmnDPWSJEmSJPWUoV6SJEmSpJ4y1EuSJEmS1FOGekm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TFHD+dC5+l23nMOLzTJIkSZI0KTfK07jGbri3rg0NDdXIyMggupYkSZKkgZvuRnkuv5ckSZIkqaecqR+wJG8DXjSm+AtV9d5BjGd94SvtJPWRr0GSJElriq+064kW3md0gJckSZIkrR6X369lSeYluWY1z90xyXCSZUm
|
||
|
"text/plain": [
|
||
|
"<Figure size 1080x5598 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plot.figure(figsize = (15, 0.25 * len(DATA_COLUMNS)))\n",
|
||
|
"importances = clf3.feature_importances_\n",
|
||
|
"stddev = np.var([t.feature_importances_ for t in clf3.estimators_], axis = 0)\n",
|
||
|
"sorted_indices = np.argsort(importances)\n",
|
||
|
"plot.barh(np.array(DATA_COLUMNS)[sorted_indices], importances[sorted_indices], xerr = stddev[sorted_indices])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 26,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"SETUP_ID_3 = 888\n",
|
||
|
"\n",
|
||
|
"reader3 = runsql('select * from computeddata where setup_id = {} order by distance asc'.format(SETUP_ID_3))\n",
|
||
|
"reader_data3 = list(reader3) # list(...) so that following cells can be repeated"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 27,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"data3 = []\n",
|
||
|
"target3 = []\n",
|
||
|
"for row in reader_data3:\n",
|
||
|
" data3 += [[float(row[c]) if row[c] != '' else math.nan for c in DATA_COLUMNS]]\n",
|
||
|
" target3 += [float(row[TARGET_COLUMN]) if row[TARGET_COLUMN] != '' else math.nan]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 28,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"data3 = imp.transform(data3)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 29,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.legend.Legend at 0x7f94a9f266d8>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 29,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA3EAAAJCCAYAAABu7U77AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzsnXeY1NT6x7/Zxi4gfekqiPS2VAvCBQtFmgUBK3ivHUXxhyLXhle9ckVFEZSrXkVFASuKFRUUAQFBVgEREVwQBBYWKQtsz++PM2dSJpnJzGR22vfzPPskOUlOziaZ5Hzzvud9FVVVQQghhBBCCCEkPkiJdgMIIYQQQgghhDiHIo4QQgghhBBC4giKOEIIIYQQQgiJIyjiCCGEEEIIISSOoIgjhBBCCCGEkDiCIo4QQgghhBBC4giKOEIIIYQQQgiJIyjiCCGEEEIIISSOoIgjhBBCCCGEkDgiLdoNAIB69eqpzZo1i3YzCCGEEEIIISQqrFu37oCqqtlOto0JEdesWTOsXbs22s0ghBBCCCGEkKigKMoOp9vSnZIQQgghhBBC4giKOEIIIYQQQgiJIyjiCCGEEEIIISSOiIkxcVaUlpZi165dKCoqinZTSAKSmZmJpk2bIj09PdpNIYQQQgghJChiVsTt2rULJ510Epo1awZFUaLdHJJAqKqKgoIC7Nq1C82bN492cwghhBBCCAmKmHWnLCoqQt26dSngiOsoioK6devSyksI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jBgxAg0
|
||
|
"text/plain": [
|
||
|
"<Figure size 1080x720 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plot.figure(figsize=(15,10))\n",
|
||
|
"xaxis = range(0, len(target3))\n",
|
||
|
"plot.plot(xaxis, target3, 'b', xaxis, clf3.predict(data3), 'r')\n",
|
||
|
"plot.legend(['TARGET OBD Speed','PREDICTED OBD Speed'])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Wir vergleichen die Prädiktion mit HERE Maps:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 30,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"RMSE = 18.76 km/h\n",
|
||
|
"NRMSE = 34.58 %\n",
|
||
|
"MAE = 14.18 km/h\n",
|
||
|
"MAP = 14.16 %\n",
|
||
|
"SMAPE = 13.26 %\n",
|
||
|
"MSD = -3.92 km/h\n",
|
||
|
"CORR = 0.80\n",
|
||
|
"ACC_A = 47.99 %\n",
|
||
|
"ACC_R = 51.85 %\n",
|
||
|
"MAD = 10.45 km/h\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"ta = target3\n",
|
||
|
"pr = clf3.predict(data3)\n",
|
||
|
"RMSE = math.sqrt(sum((ta-pr)**2)/len(ta))\n",
|
||
|
"print(\"RMSE = %.2f km/h\" %RMSE)\n",
|
||
|
"NRMSE = 1-math.sqrt(sum((ta-pr)**2))/math.sqrt(sum( (ta-np.mean(ta) )**2 ))\n",
|
||
|
"print(\"NRMSE = %.2f %%\" %(NRMSE*100))\n",
|
||
|
"MAE = sum(((ta-pr)**2)**(1/2))/len(ta)\n",
|
||
|
"print(\"MAE = %.2f km/h\" %MAE)\n",
|
||
|
"with np.errstate(divide = 'ignore'): map_elements = np.abs((ta - pr) / ta)\n",
|
||
|
"map_elements[map_elements == np.inf] = 0\n",
|
||
|
"MAP = np.sum(map_elements) / len(ta)\n",
|
||
|
"print(\"MAP = %.2f %%\" % (MAP*100))\n",
|
||
|
"SMAPE = np.sum(np.abs(ta - pr) / ((ta + pr) / 2)) / len(ta)\n",
|
||
|
"print(\"SMAPE = %.2f %%\" % (SMAPE*100))\n",
|
||
|
"MSD = np.sum(ta - pr) / len(ta)\n",
|
||
|
"print(\"MSD = %.2f km/h\" % MSD)\n",
|
||
|
"CORR = np.corrcoef(ta, pr)[1][0]\n",
|
||
|
"print(\"CORR = %.2f\" % CORR)\n",
|
||
|
"ACC_A_THRESHOLD = 10\n",
|
||
|
"ACC_A = (np.abs(ta - pr) < ACC_A_THRESHOLD).sum() / len(ta)\n",
|
||
|
"print(\"ACC_A = %.2f %%\" % (ACC_A*100))\n",
|
||
|
"ACC_R_THRESHOLD = 0.1\n",
|
||
|
"ACC_R = (np.abs(ta / pr - 1) < ACC_R_THRESHOLD).sum() / len(ta)\n",
|
||
|
"print(\"ACC_R = %.2f %%\" % (ACC_R*100))\n",
|
||
|
"MAD = np.median(np.abs(ta - pr))\n",
|
||
|
"print(\"MAD = %.2f km/h\" % MAD)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 31,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"RMSE = 21.57 km/h\n",
|
||
|
"NRMSE = 24.75 %\n",
|
||
|
"MAE = 16.79 km/h\n",
|
||
|
"MAP = 14.52 %\n",
|
||
|
"SMAPE = 15.78 %\n",
|
||
|
"MSD = 12.98 km/h\n",
|
||
|
"CORR = 0.81\n",
|
||
|
"ACC_A = 42.47 %\n",
|
||
|
"ACC_R = 35.90 %\n",
|
||
|
"MAD = 12.00 km/h\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"ta = target3\n",
|
||
|
"pr = np.array([float(d['hr_traficSpeed']) if d['hr_traficSpeed'] != '' else 0.0 for d in reader_data3])\n",
|
||
|
"pr = pr * 3.6\n",
|
||
|
"RMSE = math.sqrt(sum((ta-pr)**2)/len(ta))\n",
|
||
|
"print(\"RMSE = %.2f km/h\" %RMSE)\n",
|
||
|
"NRMSE = 1-math.sqrt(sum((ta-pr)**2))/math.sqrt(sum( (ta-np.mean(ta) )**2 ))\n",
|
||
|
"print(\"NRMSE = %.2f %%\" %(NRMSE*100))\n",
|
||
|
"MAE = sum(((ta-pr)**2)**(1/2))/len(ta)\n",
|
||
|
"print(\"MAE = %.2f km/h\" %MAE)\n",
|
||
|
"with np.errstate(divide = 'ignore'): map_elements = np.abs((ta - pr) / ta)\n",
|
||
|
"map_elements[map_elements == np.inf] = 0\n",
|
||
|
"MAP = np.sum(map_elements) / len(ta)\n",
|
||
|
"print(\"MAP = %.2f %%\" % (MAP*100))\n",
|
||
|
"SMAPE = np.sum(np.abs(ta - pr) / ((ta + pr) / 2)) / len(ta)\n",
|
||
|
"print(\"SMAPE = %.2f %%\" % (SMAPE*100))\n",
|
||
|
"MSD = np.sum(ta - pr) / len(ta)\n",
|
||
|
"print(\"MSD = %.2f km/h\" % MSD)\n",
|
||
|
"CORR = np.corrcoef(ta, pr)[1][0]\n",
|
||
|
"print(\"CORR = %.2f\" % CORR)\n",
|
||
|
"ACC_A_THRESHOLD = 10\n",
|
||
|
"ACC_A = (np.abs(ta - pr) < ACC_A_THRESHOLD).sum() / len(ta)\n",
|
||
|
"print(\"ACC_A = %.2f %%\" % (ACC_A*100))\n",
|
||
|
"ACC_R_THRESHOLD = 0.1\n",
|
||
|
"ACC_R = (np.abs(ta / pr - 1) < ACC_R_THRESHOLD).sum() / len(ta)\n",
|
||
|
"print(\"ACC_R = %.2f %%\" % (ACC_R*100))\n",
|
||
|
"MAD = np.median(np.abs(ta - pr))\n",
|
||
|
"print(\"MAD = %.2f km/h\" % MAD)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 40,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"from sklearn.preprocessing import StandardScaler\n",
|
||
|
"scaler = StandardScaler()\n",
|
||
|
"scaler.fit(data[TRAINING_RANGE[0]:TRAINING_RANGE[1]])\n",
|
||
|
"\n",
|
||
|
"scaled_training_data = scaler.transform(data[TRAINING_RANGE[0]:TRAINING_RANGE[1]])\n",
|
||
|
"scaled_data = scaler.transform(data)\n",
|
||
|
"scaled_target = np.multiply(target, 0.01)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 55,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def gridsearch_train_and_plot(base, params = {}):\n",
|
||
|
" best_clf = gridsearch(base, params)\n",
|
||
|
" best_clf.fit(scaled_training_data, scaled_target[TRAINING_RANGE[0]:TRAINING_RANGE[1]])\n",
|
||
|
" xaxis = range(0, TEST_RANGE[1])\n",
|
||
|
" print(best_clf.best_params_)\n",
|
||
|
" plot.figure(figsize=(15,10))\n",
|
||
|
" plot.axvline(x=TRAINING_RANGE[0])\n",
|
||
|
" plot.axvline(x=TRAINING_RANGE[1])\n",
|
||
|
" plot.plot(xaxis, scaled_target, 'b', xaxis, best_clf.predict(scaled_data), 'rx')\n",
|
||
|
" plot.legend(['Training','Test','TARGET OBD Speed','PREDICTED OBD Speed'])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 58,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/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"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"{}\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA20AAAJCCAYAAABTfy+dAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzs3XlYVGX7B/DvmWEVlN19DUWFUFDA3STX3NJSpHrVVk0rS1PD931N01+lmLa495aZuadluZUbpUYpKigqIuKuKYiJgiLMzPP74+bMPjDAwCDcn+uaazhnzvJwZtBzz/089yMJIcAYY4wxxhhjrHJS2LsBjDHGGGOMMcYs46CNMcYYY4wxxioxDtoYY4wxxhhjrBLjoI0xxhhjjDHGKjEO2hhjjDHGGGOsEuOgjTHGGGOMMcYqMQ7aGGOMMcYYY6wS46CNMcYYY4wxxioxDtoYY4wxxhhjrBJzsNeJfX19RdOmTe11erPOZ+YCAB7zc7NzSxhjAP9NMsYYY6xqO3r06C0hhF9x29ktaGvatCmOHDlir9ObNWL5nwCADWM72bkljDGA/yYZY4wxVrVJknTJmu24eyRjjDHGGGOMVWIctDHGGGOMMcZYJcZBG2OMMcYYY4xVYnYb08YYY4wxxlhlUlBQgKtXryIvL8/eTWFVjIuLCxo2bAhHR8dS7c9BG2OMMcYYYwCuXr2KmjVromnTppAkyd7NYVWEEAJZWVm4evUqmjVrVqpjcPdIxhhjjDHGAOTl5cHHx4cDNmZTkiTBx8enTBl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
|
"text/plain": [
|
||
|
"<Figure size 1080x720 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"from sklearn import svm\n",
|
||
|
"gridsearch_train_and_plot(svm.SVR())"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 59,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/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"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"{}\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA20AAAJCCAYAAABTfy+dAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzs3Xl8TPf6B/DPmSWLBEHUWqVKFsKETCyt1ihqLy2JWqsLore911Kl91rKr0Ust6WK3ha1VKRVitKqmlY0JRGZ2okQSi2RCpF9Muf3x5Mz+ySTZCYJfd6v17wmc+bMOd+ZTJhnnu/3eQRRFMEYY4wxxhhjrHqSVfUAGGOMMcYYY4w5xkEbY4wxxhhjjFVjHLQxxhhjjDHGWDXGQRtjjDHGGGOMVWMctDHGGGOMMcZYN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TAEmTrQN2GrUoJ+vXwdatAA++cT+ObkhN2OMMVZlOGhjjLHKdOAAXSuVwEsvAT4+dPvKFeqV5sz0yKgoCrgk9tbCyWS0X34+VYqcMAH47DPT/YJAbQays+m2QkFFUoKCLI8jBWtS1Umtli4TJtDt1FTnnztjjDHGyoWDNsYYq0wXLlAwNWMGsHEj0KgR0LUrbddoaHrksmVU0t+Ry5dpiqV54GYtLw944gla01ZUBOzda1rH5uVFAZtEEKhwCUBFUpYtM90nBWsBAaZecn37AuvX0+3hw8v9UjDGGGPMORy0McZYZVq1Cti8GVi+HJg1i5pjx8cDPXrQ/cuWmcrxO9KiBV2bB14AZe28vIAOHWh65NatNC1
|
||
|
"text/plain": [
|
||
|
"<Figure size 1080x720 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"gridsearch_train_and_plot(svm.NuSVR())"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 57,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/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",
|
||
|
"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/linear_model/stochastic_gradient.py:166: FutureWarning: max_iter and tol parameters have been added in SGDRegressor in 0.19. If both are left unset, they default to max_iter=5 and tol=None. If tol is not None, max_iter defaults to max_iter=1000. From 0.21, default max_iter will be 1000, and default tol will be 1e-3.\n",
|
||
|
" FutureWarning)\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"{'loss': 'huber'}\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA20AAAJJCAYAAAA5uN9eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzs3XucXWV9L/7PwyUCBgUhlZsC8uMWBCYxgyLqYbQCPRbQignaI2C1YECt9NCI59VATnIuGHvqBTBAKyIFISO0iLcWL2MRqWQSGAgQaACjQlEgHoUgHAis3x97MmQygSSTHfaT8H6/Xvu19nrWs9b6zl6ZefHhWc/apWmaAAAAUKfNOl0AAAAAz09oAwAAqJjQBgAAUDGhDQAAoGJCGwAAQMWENgAAgIp1NLSVUi4upTxUSrl9Lfq+rZRycylleSnluFW2PVNKGRh8XbvhKgYAAHhxdXqk7ZIkR61l318kOSnJ11az7YmmaboGX8e0qTYAAICO62hoa5rm+iS/WbmtlLJXKeWfSykLSik/LqXsN9h3SdM0tyV5thO1AgAAdEKnR9pW56IkH2+a5g1JzkjypbXYZ6tSyvxSyk9LKe/esOUBAAC8eLbodAErK6WMTfLmJF8vpaxoftla7Lp70zQPlFJel+SHpZSFTdPcu6HqBAAAeLFUFdrSGvn7bdM0XeuyU9M0Dwwu7yul/CjJhCRCGwAAsNGr6vbIpmkeTfKzUsr7kqS0HPxC+5RSti+lvGzw/Y5JDkty5wYvFgAA4EVQmqbp3MlLuSLJ4Ul2TPLrJGcn+WGSOUl2TrJlkiubpplZSulO8k9Jtk/yZJJfNU1zQCnlzUkuTOsBJZsl+XzTNF9+sX8WAACADaGjoQ0AAIAXVtXtkQAAAAzXsQeR7Ljjjs0ee+zRqdOv1n0PP54ked24l3e4EiDxOwkAbNoWLFjwSNM049bUr2OhbY899sj8+fM7dfrVmnLhvyVJ5p5yaIcrARK/kwDApq2U8vO16ef2SAAAgIoJbQAAABUT2gAAACrWsTltAABQk6effjr3339/nnzyyU6XwiZmq622ym677ZYtt9xyVPsLbQAAkOT+++/Ptttumz322COllE6XwyaiaZosXbo0999/f/bcc89RHcPtkQAAkOTJJ5/MDjvsILDRVqWU7LDDDus1giu0AQDAIIGNDWF9/10JbQAAABUT2gAAoAJLly5NV1dXurq6stNOO2XXXXcdWn/qqafW6hgf+tCHcvfdd79gn/PPPz+XX355O0rmReJBJAAAUIEddtghAwMDSZIZM2Zk7NixOeOMM4b1aZomTdNks81WP/byla98ZY3nOe2009a/WF5URtoAAKBi99xzT8aPH58//dM/zQEHHJAHH3wwJ598ciZNmpQDDjggM2fOHOr7lre8JQMDA1m+fHm22267nHnmmTn44INz6KGH5qGHHkqS/PVf/3U+//nPD/U/88wzc8ghh2TffffNjTfemCR5/PHH8973vjfjx4/Pcccdl0mTJg0FSl58RtoAAGAV//2bd+TO/3i0rcccv8srcvbRB4xq37vuuiuXXnppJk2alCQ555xz8qpXvSrLly9PT09PjjvuuIwfP37YPr/73e/yn/7Tf8o555yTv/zLv8zFF1+cM888c8Sxm6bJvHnzcu2112bmzJn553/+55x77rnZaaedcvXVV+fWW2/NxIkTR1U37WGkDQAAKrfXXnsNBbYkueKKKzJx4sRMnDgxixYtyp133jlin6233jp/9Ed/lCR5wxvekCVLlqz22H/yJ38yos8NN9yQ448/Pkly8MEH54ADRhc2aQ8jbQAAsIrRjohtKC9/+cuH3i9evDhf+MIXMm/evGy33Xb5L//lv6z2O8DGjBkz9H7zzTfP8uXLV3vsl73sZWvsQ2cZaQMAgI3Io48+mm233TaveMUr8uCDD+Zf/uVf2n6Oww47LL29vUmShQsXrnYkjxePkTYAANiITJw4MePHj89+++2X3XffPYcddljbz/Hxj388J5xwQsaPHz/0euUrX9n287B2StM0HTnxpEmTmvnz53fk3M9nyoX/liSZe8qhHa4ESPxOAvDiWrRoUfbff/9Ol1GF5cuXZ/ny5dlqq62yePHiHHHEEVm8eHG22MKYz2it7t9XKWVB0zSTnmeXIT51AABgmGXLluUd73hHli9fnqZpcuGFFwpsHeSTBwAAhtluu+2yYMGCTpfBIA8iAQAAqJiRNgCA9VFKpyuo32abJc880+kqYKNlpA0AYH2MHdvpCur32td2ugLYqAltAADr47HHBLcXssceyc9+1ukqYKMmtAEArK/HHut0BfUS2Nba0qVL09XVla6uruy0007Zddddh9afeuqptT7OxRdfnF/96lcbsFJebOa0AQCsr2237XQF9dpzT8FtLe2www4ZGBhIksyYMSNjx47NGWecsc7HufjiizNx4sTstNNO7S6RDhHaAADWx7bbJsuWdbqKei1ZIri1wVe/+tWcf/75eeqpp/LmN7855513Xp599tl86EMfysDAQJqmycknn5xXv/rVGRgYyJQpU7L11ltn3rx5GTNmTKfLZz0JbQAA60NgW7Nf/KLTFayz//7NO3Lnfzza1mOO3+UVOfvoA9Z5v9tvvz3/9E//lBtvvDFbbLFFTj755Fx55ZXZa6+98sgjj2ThwoVJkt/+9rfZbrvtcu655+a8885LV1dXW+unc4Q2AID10TSdroBN3Pe///309/dn0qRJSZInnngir3nNa3LkkUfm7rvvzic+8Ym8613vyhFHHNHhStlQhDYAAFjFaEbENpSmafJnf/ZnmTVr1ohtt912W7773e/m/PPPz9VXX52LLrqoAxWyoXl6JAAAVOwP//AP09vbm0ceeSRJ6ymTv/jFL/Lwww+naZq8733vy8yZM3PzzTcnSbbddts85ommmxQjbQAAULEDDzwwZ599dv7wD/8wzz77bLbccstccMEF2XzzzfPhD384TdOklJLPfOYzSZIPfehD+chHPuJBJJsQoQ0AACozY8aMYesf+MAH8oEPfGBEv1tuuWVE2+TJkzN58uQNVRod4PZIAACAigltAAAAFRPaAAAAKia0AQAAVExoAwAAqJjQBgBAe8yenfT1DW/r62u1A6MmtAEA0B7d3cnkyc8Ft76+1np3d2fr2kgsXbo0XV1d6erqyk477ZRdd911aP2pp57KNddck1JK7rrrrqF9lixZkq233jpdXV0ZP358TjjhhDz99NND2+fNm5fDDz88e++9dyZOnJh3vetdWbhwYZLW1wqsfI6urq7MnTt36P3YsWOz7777pqurKyeccMKIeu+44468/e1vz7777pu99947s2bNStM0SZJLLrkk48aNS1dXVw444IAcd9xx+f3vfz/ivHvvvXf+5E/+JHfeeedqP5Of/vSneeMb35iurq7sv//+I74Kod0uueSSfOxjH9ug5xgNoQ0AgPbo6Ul6e1tB7ayzWsve3lY7a7TDDjtkYGAgAwMD+ehHP5rTTz99aH3MmDG54oor8pa3vCVXXHHFsP322muvDAwMZOHChbn//vvT29ubJPn1r3+dyZMn53/9r/+VxYsX5+abb86nP/3p3HvvvUP7rnyOgYGBTJkyZej9pEmTcvnll2dgYCCXXnrpsHM+8cQTOeaYY3LmmWfm7rvvzq233pobb7wxX/rSl4b6rDjWHXfckTFjxmTu3Lkjzrt48eJMmTIlb3/72/Pwww+P+ExOPPHEXHTRRRkYGMjtt9/+kv3+OaENAID26elJpk5NZs1qLQW2tli2bFluuOGGfPnLX86VV1652j6bb755DjnkkDzwwANJkvPOOy8nnnhi3vzmNw/1ectb3pJ3v/vd613P1772tRx22GE54ogjkiTbbLNNzjvvvJxzzjkj+i5fvjyPP/54tt9++9Uea8qUKTniiCPyta99bcS2hx56KDvvvPPQzzd+/PgkrdG6D37wgzn00EOz99575+/+7u+G9vnsZz+b7u7uHHTQQTn77LOH2i+77LIccsgh6erqyimnnJJ
|
||
|
"text/plain": [
|
||
|
"<Figure size 1080x720 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"from sklearn import linear_model\n",
|
||
|
"gridsearch_train_and_plot(linear_model.SGDRegressor(),\n",
|
||
|
" {'loss': ['squared_loss', 'huber', 'epsilon_insensitive', 'squared_epsilon_insensitive']})"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 62,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"{'n_neighbors': 10, 'weights': 'distance'}\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA20AAAJCCAYAAABTfy+dAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzsnXl4VEX297+dpLNiAiQsAmERgSQIJCHEAKJgBIWEuCE4OohrmKjjDA4qzjsR1FkIGkQBRf2Ng9sAjs7gPm7NjCKOLBIBQYwgKqisyiYBktT7x8npW3379prudELO53nu0923762qW3erb51Tp2xKKQiCIAiCIAiCIAjNk6hIF0AQBEEQBEEQBEHwjIg2QRAEQRAEQRCEZoyINkEQBEEQBEEQhGaMiDZBEARBEARBEIRmjIg2QRAEQRAEQRCEZoyINkEQBEEQBEEQhGaMiDZBEARBEARBEIRmjIg2QRAEQRAEQRCEZoyINkEQBEEQBEEQhGZMTKQyTktLUz179oxU9pZs33sUAHBGh6QIl0QQBEDuSUEQBEEQTm3WrVu3TynVwdd2ERNtPXv2xNq1ayOVvSWTHv8IALBs6tAIl0QQBEDuSUEQBEEQTm1sNtvX/mwn7pGCIAiCIAiCIAjNGBFtgiAIgiAIgiAIzRgRbYIgCIIgCIIgCM2YiI1pEwRBEARBEITmxMmTJ7Fz507U1NREuijCKUZ8fDy6desGu90e1P4i2gRBEARBEAQBwM6dO3HaaaehZ8+esNlskS6OcIqglML+/fuxc+dO9OrVK6g0xD1SEARBEARBEADU1NQgNTVVBJsQUmw2G1JTUxtlwRXRJgiCIAiCIAgNiGATwkFjrysRbYIgCIIgCIIgCM0YEW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67l+Zqy8kBevaMaNEEQRBaHfv370d2djays7PRuXNndO3a1fn7xIkTWL58OWw2Gz7//HPnPjt27EBCQgKys7ORlZWFa665BidPnnT+v3r1aowcORJ9+vRBbm4uioqKsHHjRgA0rYCeR3Z2NpYtW+b83qZNG/Tr1w/Z2dm45ppr3Mr72Wef4fzzz0e/fv3Qp08f3H///VBKAQAWL16MDh06IDs7G/3798eECRPw888/u+Xbp08fXHbZZdi8ebNlnfzvf//D2WefjezsbGRmZrpNhRBqFi9ejFtvvTWseQSDiDZBEIRWDIu2+HggOZkCk3z3Hf2nFC2CIAhC05CamoqqqipUVVXhV7/6FaZNm+b8HRsbiyVLluCcc87BkiVLXPbr3bs3qqqqsHHjRuzcuRMvvPACAGD37t2YOHEi/vznP6O6uhqffPIJ7r77bmzbts25r55HVVUVJk2a5Pyel5eH559/HlVVVXjmmWdc8jx27BhKSkowY8YMbN26FZ9++ilWrVqFRx991LkNp/XZZ58hNjYWy5Ytc8u3uroakyZNwvnnn4+9e/e61cmUKVPwxBNPoKqqCps2bWq188+JaBMEQWjFHDxIYg0AOnWiwCSffWb8z1MCCIIgCJHlyJEjWLlyJf76179i6dKllttER0cjPz8fu3btAgAsWLAAU6ZMwbBhw5zbnHPOObjkkksaXZ6///3vGD58OMaMGQMASExMxIIFCzB79my3bWtra3H06FG0a9fOMq1JkyZhzJgx+Pvf/+723549e3D66ac7jy8rKwsAWesmT56MoUOHok+fPnjyySed+zzwwAMYMmQIBg4ciJkzZzrXP/fcc8jPz0d2djamTp2Kuro6AMDf/vY39O3bF/n5+fjwww+DrJHwEhPpAgiCIAiRg8e0ARRF8ttvgXvvNf6//XbA4h0qCIJwyvPb39L43lCSnQ3Mmxfcvi+//DIuuugi9O3bF6mpqVi3bh0GDx7
|
||
|
"text/plain": [
|
||
|
"<Figure size 1080x720 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"from sklearn import neighbors\n",
|
||
|
"gridsearch_train_and_plot(neighbors.KNeighborsRegressor(),\n",
|
||
|
" {'n_neighbors': [5, 10, 20, 50, 100, 200, 500],\n",
|
||
|
" 'weights': ['uniform', 'distance']})"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 61,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"ename": "ValueError",
|
||
|
"evalue": "Input contains NaN, infinity or a value too large for dtype('float64').",
|
||
|
"output_type": "error",
|
||
|
"traceback": [
|
||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
|
"\u001b[0;31m_RemoteTraceback\u001b[0m Traceback (most recent call last)",
|
||
|
"\u001b[0;31m_RemoteTraceback\u001b[0m: \n\"\"\"\nTraceback (most recent call last):\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/externals/joblib/externals/loky/process_executor.py\", line 418, in _process_worker\n r = call_item()\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/externals/joblib/externals/loky/process_executor.py\", line 272, in __call__\n return self.fn(*self.args, **self.kwargs)\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/externals/joblib/_parallel_backends.py\", line 567, in __call__\n return self.func(*args, **kwargs)\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/externals/joblib/parallel.py\", line 225, in __call__\n for func, args, kwargs in self.items]\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/externals/joblib/parallel.py\", line 225, in <listcomp>\n for func, args, kwargs in self.items]\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/model_selection/_validation.py\", line 568, in _fit_and_score\n test_scores = _score(estimator, X_test, y_test, scorer, is_multimetric)\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/model_selection/_validation.py\", line 605, in _score\n return _multimetric_score(estimator, X_test, y_test, scorer)\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/model_selection/_validation.py\", line 635, in _multimetric_score\n score = scorer(estimator, X_test, y_test)\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/metrics/scorer.py\", line 98, in __call__\n **self._kwargs)\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/metrics/regression.py\", line 239, in mean_squared_error\n y_true, y_pred, multioutput)\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/metrics/regression.py\", line 77, in _check_reg_targets\n y_pred = check_array(y_pred, ensure_2d=False)\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/utils/validation.py\", line 573, in check_array\n allow_nan=force_all_finite == 'allow-nan')\n File \"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/utils/validation.py\", line 56, in _assert_all_finite\n raise ValueError(msg_err.format(type_err, X.dtype))\nValueError: Input contains NaN, infinity or a value too large for dtype('float64').\n\"\"\"",
|
||
|
"\nThe above exception was the direct cause of the following exception:\n",
|
||
|
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
|
||
|
"\u001b[0;32m<ipython-input-61-fd370c5170f8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m gridsearch_train_and_plot(neighbors.RadiusNeighborsRegressor(),\n\u001b[1;32m 2\u001b[0m {'radius': [0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1.0],\n\u001b[0;32m----> 3\u001b[0;31m 'weights': ['uniform', 'distance']})\n\u001b[0m",
|
||
|
"\u001b[0;32m<ipython-input-55-5a1002d430f5>\u001b[0m in \u001b[0;36mgridsearch_train_and_plot\u001b[0;34m(base, params)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mgridsearch_train_and_plot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbase\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparams\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mbest_clf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgridsearch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbase\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mbest_clf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mscaled_training_data\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mscaled_target\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mTRAINING_RANGE\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mTRAINING_RANGE\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mxaxis\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mTEST_RANGE\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbest_clf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbest_params_\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m~/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/model_selection/_search.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y, groups, **fit_params)\u001b[0m\n\u001b[1;32m 720\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresults_container\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 721\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 722\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_run_search\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mevaluate_candidates\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 723\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 724\u001b[0m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresults_container\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m~/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/model_selection/_search.py\u001b[0m in \u001b[0;36m_run_search\u001b[0;34m(self, evaluate_candidates)\u001b[0m\n\u001b[1;32m 1189\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_run_search\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mevaluate_candidates\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1190\u001b[0m \u001b[0;34m\"\"\"Search all candidates in param_grid\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1191\u001b[0;31m \u001b[0mevaluate_candidates\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mParameterGrid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparam_grid\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1192\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1193\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m~/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/model_selection/_search.py\u001b[0m in \u001b[0;36mevaluate_candidates\u001b[0;34m(candidate_params)\u001b[0m\n\u001b[1;32m 709\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mparameters\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtest\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 710\u001b[0m in product(candidate_params,\n\u001b[0;32m--> 711\u001b[0;31m cv.split(X, y, groups)))\n\u001b[0m\u001b[1;32m 712\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 713\u001b[0m \u001b[0mall_candidate_params\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mextend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcandidate_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m~/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/externals/joblib/parallel.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, iterable)\u001b[0m\n\u001b[1;32m 928\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 929\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_backend\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mretrieval_context\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 930\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mretrieve\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 931\u001b[0m \u001b[0;31m# Make sure that we get a last message telling us we are done\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 932\u001b[0m \u001b[0melapsed_time\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_start_time\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m~/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/externals/joblib/parallel.py\u001b[0m in \u001b[0;36mretrieve\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 831\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 832\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_backend\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'supports_timeout'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 833\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_output\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mextend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mjob\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 834\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 835\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_output\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mextend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mjob\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m~/Studium/IDP/repo/Python/_venv/lib/python3.7/site-packages/sklearn/externals/joblib/_parallel_backends.py\u001b[0m in \u001b[0;36mwrap_future_result\u001b[0;34m(future, timeout)\u001b[0m\n\u001b[1;32m 519\u001b[0m AsyncResults.get from multiprocessing.\"\"\"\n\u001b[1;32m 520\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 521\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 522\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mLokyTimeoutError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 523\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mTimeoutError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m/usr/lib/python3.7/concurrent/futures/_base.py\u001b[0m in \u001b[0;36mresult\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 430\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mCancelledError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 431\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_state\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mFINISHED\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 432\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__get_result\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 433\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 434\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mTimeoutError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m/usr/lib/python3.7/concurrent/futures/_base.py\u001b[0m in \u001b[0;36m__get_result\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 382\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__get_result\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 383\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_exception\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 384\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_exception\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 385\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 386\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_result\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;31mValueError\u001b[0m: Input contains NaN, infinity or a value too large for dtype('float64')."
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# i think something is borked in there\n",
|
||
|
"gridsearch_train_and_plot(neighbors.RadiusNeighborsRegressor(),\n",
|
||
|
" {'radius': [0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1.0],\n",
|
||
|
" 'weights': ['uniform', 'distance']})"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 63,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"/home/markus/Studium/IDP/repo/Python/_venv/lib/python3.7/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"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"{'normalize_y': True}\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA20AAAJCCAYAAABTfy+dAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzs3Xl4FGX2NuCnspFACIFs7FskgSCYYECRRVBAXACdQcAN1HEEd3FQcT4RhHF+DK4joqCjgw7K4obiMiKKA4hAQAJhD4GghCWQAAlLyFbfHyfVS9JJeqnq6nQ/93X1Vd3V1VUvSUj69DnveRVVVUFERERERES+KcjsARAREREREVHtGLQRERERERH5MAZtREREREREPoxBGxERERERkQ9j0EZEREREROTDGLQRERERERH5MAZtREREREREPoxBGxERERERkQ9j0EZEREREROTDQsy6cGxsrNqxY0ezLu/QgRPnAACd45qYPBIiAvh/koiIiPzbli1bTqqqGlffcaYFbR07dsTmzZvNurxDYxf8AgBYOrGvySMhIoD/J4mIiMi/KYpyyJnjWB5JRERERETkwxi0ERERERER+TAGbURERERERD7MtDltRERERES+pKysDIcPH0ZJSYnZQyE/Ex4ejrZt2yI0NNSt1zNoIyIiIiICcPjwYTRt2hQdO3aEoihmD4f8hKqqKCgowOHDh9GpUye3zsHySCIiIiIiACUlJYiJiWHARrpSFAUxMTEeZXAZtBERERERVWHARkbw9OeKQRsREREREZEPY9BGREREROQDCgoKkJqaitTUVLRs2RJt2rSxPC4tLXXqHPfccw/27t1b5zHz5s3Dhx9+qMeQyUvYiISIiIiIyAfExMQgMzMTADBjxgxERkZiypQpdseoqgpVVREU5Dj38u9//7ve6zz00EOeD5a8ipk2IiIiIiIftn//fqSkpO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MxOZmZmYNGkSJk+ebHkcFhaGxYsXo3///li8eLHd6xITE5GZmYmsrCwcPnwYy5YtAwAcP34cY8aMwd///ndkZ2fj119/xTPPPIOcnBzLa22vkZmZibFjx1rup6en48MPP0RmZiY++OADu2teuHABI0eOxNSpU7F3715s27YN69evx5tvvmk5RjvXzp07ERYWhqVLl9a4bnZ2NsaOHYtrrrkGJ06cqPE1mTBhAt5++21kZmZix44dAbv+HIM2IqIAduaMBGsAkJAgjUl27rQ+ry0JQERE5jp79izWrVuHd999F0uWLHF4THBwMPr06YO8vDwAwBtvvIEJEybgqquushzTv39/3HzzzR6P56OPPkK/fv0wbNgwAEDjxo3xxhtvYPbs2TWOLS8vx7lz59C8eXOH5xo7diyGDRuGjz76qMZz+fn5aNWqleXfl5KSAkCydXfddRf69u2LLl264J133rG85sUXX0Tv3r3Rs2dPTJ8+3bJ/0aJF6NOnD1JTUzFx4kRUVFQAAP79738jKSkJffr0wc8//+zmV8RYIWYPgIiIzKPNaQOki+TvvwPPP299/oknAAd/Q4mI/N7jj8v8Xj2lpgKvvebea7/44gsMHz4cSUlJiImJwZYtW3D55ZfbHVNSUoKNGzfin//8JwApX5wwYUKd53311VexaNEiAEDz5s2xevVqp8azc+fOGtdPTEzE2bNnUVTVinjp0qVYt24djh49iqSkJIwYMaLW8/Xq1cuu7FMzefJkJCcnY9CgQRg+fDgmTJiA8PBwAMD27duxYcMGnDt3DmlpabjxxhuxY8cOZGdnY9OmTVBVFSNHjsSaNWsQFxeHpUuX4ueff0ZoaCgefPBBfPjhhxg6dCi
|
||
|
"text/plain": [
|
||
|
"<Figure size 1080x720 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"from sklearn import gaussian_process\n",
|
||
|
"gridsearch_train_and_plot(gaussian_process.GaussianProcessRegressor(),\n",
|
||
|
" {'normalize_y': [True, False]})"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "IDP",
|
||
|
"language": "python",
|
||
|
"name": "idpenv"
|
||
|
},
|
||
|
"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.4"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 2
|
||
|
}
|