This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
['Tokyo', 'New York', 'Mexico City', 'Mumbai', 'São Paulo', 'Delhi', | |
'Shanghai', 'Kolkata', 'Los Angeles', 'Dhaka', 'Buenos Aires', | |
'Karachi', 'Cairo', 'Rio de Janeiro', 'Ōsaka', 'Beijing', 'Manila', | |
'Moscow', 'Istanbul', 'Paris', 'Seoul', 'Lagos', 'Jakarta', | |
'Guangzhou', 'Chicago', 'London', 'Lima', 'Tehran', 'Kinshasa', | |
'Bogotá', 'Shenzhen', 'Wuhan', 'Hong Kong', 'Tianjin', 'Chennai', | |
'Taipei', 'Bengalūru', 'Bangkok', 'Lahore', 'Chongqing', 'Miami', | |
'Hyderabad', 'Dallas', 'Santiago', 'Philadelphia', | |
'Belo Horizonte', 'Madrid', 'Houston', 'Ahmadābād', | |
'Ho Chi Minh City', 'Washington', 'Atlanta', 'Toronto', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
['Tokyo', 'New York', 'Mexico City', 'Mumbai', 'São Paulo', 'Delhi', | |
'Shanghai', 'Kolkata', 'Los Angeles', 'Dhaka', 'Buenos Aires', | |
'Karachi', 'Cairo', 'Rio de Janeiro', 'Ōsaka', 'Beijing', 'Manila', | |
'Moscow', 'Istanbul', 'Paris', 'Seoul', 'Lagos', 'Jakarta', | |
'Guangzhou', 'Chicago', 'London', 'Lima', 'Tehran', 'Kinshasa', | |
'Bogotá', 'Shenzhen', 'Wuhan', 'Hong Kong', 'Tianjin', 'Chennai', | |
'Taipei', 'Bengalūru', 'Bangkok', 'Lahore', 'Chongqing', 'Miami', | |
'Hyderabad', 'Dallas', 'Santiago', 'Philadelphia', | |
'Belo Horizonte', 'Madrid', 'Houston', 'Ahmadābād', | |
'Ho Chi Minh City', 'Washington', 'Atlanta', 'Toronto', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TSP(): | |
cities = None | |
santa = None | |
variables_dict = None | |
x = None | |
path = None | |
sec_constraints = 0 | |
execution_time = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ID | y | X0 | X1 | X2 | X3 | X4 | X5 | X6 | X8 | X10 | X11 | X12 | X13 | X14 | X15 | X16 | X17 | X18 | X19 | X20 | X21 | X22 | X23 | X24 | X26 | X27 | X28 | X29 | X30 | X31 | X32 | X33 | X34 | X35 | X36 | X37 | X38 | X39 | X40 | X41 | X42 | X43 | X44 | X45 | X46 | X47 | X48 | X49 | X50 | X51 | X52 | X53 | X54 | X55 | X56 | X57 | X58 | X59 | X60 | X61 | X62 | X63 | X64 | X65 | X66 | X67 | X68 | X69 | X70 | X71 | X73 | X74 | X75 | X76 | X77 | X78 | X79 | X80 | X81 | X82 | X83 | X84 | X85 | X86 | X87 | X88 | X89 | X90 | X91 | X92 | X93 | X94 | X95 | X96 | X97 | X98 | X99 | X100 | X101 | X102 | X103 | X104 | X105 | X106 | X107 | X108 | X109 | X110 | X111 | X112 | X113 | X114 | X115 | X116 | X117 | X118 | X119 | X120 | X122 | X123 | X124 | X125 | X126 | X127 | X128 | X129 | X130 | X131 | X132 | X133 | X134 | X135 | X136 | X137 | X138 | X139 | X140 | X141 | X142 | X143 | X144 | X145 | X146 | X147 | X148 | X150 | X151 | X152 | X153 | X154 | X155 | X156 | X157 | X158 | X159 | X160 | X161 | X162 | X163 | X164 | X165 | X166 | X167 | X168 | X169 | X170 | X171 | X172 | X173 | X174 | X175 | X176 | X177 | X178 | X179 | X180 | X181 | X182 | X183 | X184 | X185 | X186 | X187 | X189 | X190 | X191 | X192 | X194 | X195 | X196 | X197 | X198 | X199 | X200 | X201 | X202 | X203 | X204 | X205 | X206 | X207 | X208 | X209 | X210 | X211 | X212 | X213 | X214 | X215 | X216 | X217 | X218 | X219 | X220 | X221 | X222 | X223 | X224 | X225 | X226 | X227 | X228 | X229 | X230 | X231 | X23 |
---|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def preprocessing(): | |
# Read input data | |
train = pd.read_csv("train.csv") | |
categorical = ["X0", "X1", "X2", "X3", "X4", "X5", "X6", "X8"] | |
# Convert categorical data | |
for c in categorical: | |
group_by = train.groupby(by=c)["y"].mean().reset_index().rename(columns={"y": "{}_converted".format(c)}) | |
train = pd.merge(train, group_by, how='inner', on=c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param_grid = {'learning_rate': [float(v) for v in np.arange(0.01, 0.25, 0.01)], | |
'colsample_bytree': [float(v) for v in np.arange(0.8, 1.01, 0.1)], | |
'subsample': [float(v) for v in np.arange(0.5, 1.01, 0.1)], | |
'n_estimators': [int(v) for v in np.arange(100, 3000, 100)], | |
'reg_alpha': [float(v) for v in np.arange(0.01, 0.5, 0.05)], | |
'max_depth': [int(v) for v in np.arange(3, 14, 1)], | |
'gamma': [int(v) for v in np.arange(0, 10, 2)] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_grid_iterable(): | |
param_grid = {'learning_rate': [float(v) for v in np.arange(0.01, 0.25, 0.01)], | |
'colsample_bytree': [float(v) for v in np.arange(0.8, 1.01, 0.1)], | |
'subsample': [float(v) for v in np.arange(0.5, 1.01, 0.1)], | |
'n_estimators': [int(v) for v in np.arange(100, 3000, 100)], | |
'reg_alpha': [float(v) for v in np.arange(0.01, 0.5, 0.05)], | |
'max_depth': [int(v) for v in np.arange(3, 14, 1)], | |
'gamma': [int(v) for v in np.arange(0, 10, 2)] | |
} | |
grid_iter = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read input data | |
X, y = preprocessing() | |
# Create dataframe to collect the results | |
tests_columns = ["test_nr", "cv_mean", "cv_min", "cv_max", "cv_median", "params"] | |
test_id = 0 | |
tests = pd.DataFrame(columns=tests_columns) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import r2_score | |
def xgb_r2_score(preds, dtrain): | |
labels = dtrain.get_label() | |
return 'r2', r2_score(labels, preds) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imports | |
import numpy as np | |
import pandas as pd | |
import xgboost as xgb | |
from interruptingcow import timeout | |
from sklearn.model_selection import KFold # import KFold | |
from sklearn.metrics import r2_score | |
import json | |
from preprocessing import preprocessing, xgb_r2_score # The preprocessing and the r2 evaluation | |
from generate_grid import get_grid_iterable # The grid |