3rd Place Solution for HomeDepot Product Search Results Relevance Competition on Kaggle.
Turing Test's Solution for Home Depot Product Search Relevance Competition on Kaggle
| Submission | CV RMSE | Public LB RMSE | Private LB RMSE | Position | | :--- | :-------: | :--------------: | :---------------: | :------------------: | | Simplified Single Model from Igor and Kostia (10 features) | 0.44792 | 0.45072 | 0.44949 | 31 | | Best Single Model from Igor and Kostia | 0.43787 | 0.44017 | 0.43895 | 11 | | Best Single Model from Chenglong | 0.43832 | 0.43996 | 0.43811 | 9 | | Best Ensemble Model from Igor and Kostia | - | 0.43819 | 0.43704 | 8 | | Best Ensemble Model from Chenglong | 0.43550 | 0.43555 | 0.43368 | 6 | | Best Final Ensemble Model | - | 0.43433| 0.43271 | 3 |
Before proceeding, one should place all the data from the competition website into folder
Note that in the following, all the commands and scripts are executed and run in directory
We used Python 3.5.1 and modules comes with Anaconda 2.4.1 (64-bit). In addition, we also used the following libraries and modules: - gensim 0.12.4 - hyperopt 0.0.3.dev - keras 0.3.2 - matplotlib-venn 0.11.3 - python-Levenshtein 0.12.0 - regex 2.4.85 - xgboost 0.4
We used the following packages installed via
install.packages(): - data.table - Rtsne
We used the following thirdparty packages: - rgf 1.2
We used glove-gensim to convert GloVe vectors into Word2Vec format for easy usage with Gensim. After that, put all the models in the corresponding directory (see
We also used the following external data: - Color data from this Kaggle forum post, i.e.,
./Data/dict/color_data.pyin this repo. - Google spelling correction dictionary from this Kaggle forum post, i.e.,
google_spelling_checker_dict.pyin this repo. - Home-made word replacement dictionary, i.e.,
./Data/dict/word_replacer.csvin this repo. - NLTK corpora and taggers data downloaded using
To generate data and features, one should run
python run_data.py. While we have tried our best to make things as parallelism and efficient as possible, this part might still take 1 ~ 2 days to finish, depending on the computational power. So be patient :)
Note that various text processing are useful for introducing diversity into ensemble. As a matter of fact, one feature set (i.e.,
basic20160313) from our final solution is generated before the Fixing Typos post, i.e., not using the Google spelling correction dictionary. Such version of features can be generated by turning off the
After team merging with Igor&Kostia, we have rebuilt everything from scratch, and most of our models used different subsets of Igor&Kostia's features. For this reason, you should also need to generate their features. Since Igor&Kostia's features are in
.csvdataframe format, we provide a converter
turing_test_converter.pyto convert them to the format we use, i.e.,
In step 3, we have generated a few thousands of features. However, only part of them will be used to build our model. For example, we don't need those features that have very little predictive power (e.g., have very small correlation with the target relevance.) Thus we need to do some feature selection.
In our solution, feature selection is enabled via the following two successive steps.
This approach is implemented as
get_feature_conf_*.py. The general idea is to include or exclude specific features via
regexoperations of the feature names. For example, - one can specify the features that he want to include via the
MANDATORY_FEATSvariable, despite of its correlation with the target - one can also specify the features that he want to exclude via the
COMMENT_OUT_FEATSvariable, despite of its correlation with the target (
MANDATORY_FEATShas higher priority than
The output of this is a feature conf file. For example, after running the following command:
python get_feature_conf_nonlinear.py -d 10 -o feature_conf_nonlinear_201605010058.py
./conf/feature_conf_nonlinear_201605010058.pywhich contains a feature dictionary specifying the features to be included in the following step.
One can play around with
COMMENT_OUT_FEATSto generate different feature subset. We have included in
./confa few other feature confs from our final submission. Among them,
feature_conf_nonlinear_201604210409.pyis used to build the best single model.
With the above generated feature conf, one can combine all the features into a feature matrix via the following command:
python feature_combiner.py -l 1 -c feature_conf_nonlinear_201604210409 -n basic_nonlinear_201604210409 -t 0.05
-t 0.05above is used to enable the correlation base feature selection. In this case, it means: drop any feature that has a correlation coef lower than
0.05with the target relevance.
TODO(Chenglong): Explore other feature selection strategies, e.g., greedy forward feature selection (FFS) and greedy backward feature selection (BFS).
In our solution, a
taskis an object composite of a specific
basic_nonlinear_201604210409) and a specific
XGBoostRegressorfrom xgboost). The definitions for
Take the following command for example.
python task.py -m single -f basic_nonlinear_201604210409 -l reg_xgb_tree -e 100
reg_xgb_tree. - The
taskis optimized with hyperopt for
100evals for searching the best parameters for
reg_xgb_tree. - The
taskperforms both CV and final refit. CV in this case has two purposes: 1) guide hyperopt to find the best parameters, and 2) generate predictions for each CV fold for further (2nd and 3rd level) stacking. - For all the available learners and the corresponding parameter searching space, please see
During the competition, we have run various tasks (i.e., various features and various learners) to generate a diverse 1st level model library. Please see
./Log/level1_modelsfor all the tasks we have included in our final submission.
After generating the
basic_nonlinear_201604210409(see step 4 how to generate this), run the following command to generate the best single model:
python task.py -m single -f basic_nonlinear_201604210409 -l reg_xgb_tree_best_single_model -e 1
This should generate a submission with local CV RMSE around 0.438 ~ 0.439.
After building some diverse 1st level models, run the following command to generate the best ensemble model:
python run_stacking_ridge.py -l 2 -d 0 -t 10 -c 1 -L reg_ensemble -o
This should generate a submission with local CV RMSE around 0.436.
Before proceeding, one should specify correct paths in file
config_IgorKostia.pyand place all the data from the competition website into folder specified by variable
DATA_DIR. To reproduce our
Ensemble_Bfrom Step IK5 one should place the used feature sets into folder specified by variable
FEATURESETS_DIR. Note that in the following, all the commands and scripts are executed and run in directory
We used Python 2.7.11 on Windows platform and modules comes with Anaconda 2.4.0 (64-bit), including: - scikit-learn 0.17.1 - numpy 1.10.1 - pandas 0.17.0 - re 2.2.1 - matplotlib 1.4.3 - scipy 0.16.0
In addition, we also used the following libraries and modules: - NLTK 3.1 (use
nltk.download()command) - gensim 0.12.2 - xgboost 0.4
Some descriptive analysis and final model blending was also done in Excel 2007 and Excel 2010.
We do all text preprocessing before any feature generation and save the results to files. It helped us save a few computing days since the same preprocessing steps are necessary to generate different features. - Run
text_processing.py. - Run
The necessary replacement data is loaded automatically from files
We need to run consequently the following files: -
To generate features without using the Google dictionary, we also need to run: -
As a result, we will have a few csv files with the necessary features for model building.
One part of the ensemble
Ensemble_Ais generated from the following code: -
To get the other part
Ensemble_B, we need to run these files: -
ensemble_script_imitation_version.py(It just reproduces the selection of random features generated from
ensemble_script_random_version.py. You do not need to run
These two parts can be generated in parallel. Our final submission from Igor&Kostia was then prodused in Excel as:
So, we had two ensembles prepared using different methodologies. We observed that our ensembles behave differently in different parts of the datasets (
163700 < id <= 221473,
id > 221473. Since we observed regular patterns in the data as well, we thought that one of the ensembles might be especially prone to overfitting in some parts. So, while blending our ensembles for final submissions, we made different bets assuming that in some parts one of the models would behave much worse in private than in public.
Our two final submission were produced in Excel with the weights from the table below (the weight for Chenglong's and Igor&Kostia's parts add up to 1). Both these submissions scored the same
0.43271on the private leaderboard.
| | Weight Chenglong for
part2| Weight Chenglong for
part3| Public LB RMSE | Private LB RMSE | | :-----------------: | :---------: | :---------: | :---------------: | :---------------: | | Submission 1 | 0.75 | 0.8 | 0.43443 | 0.43271 | | Submission 2 | 0.6 | 0.3 | 0.43433 | 0.43271 |