Kaggle competition: Elo Merchant Category Recommendation
<SOS> metric: RMSE Kaggle data source: elo-merchant-category-recommendation<save_to_csv>
List = ['old_duration_min', 'old_purchase_date_uptonow', 'new_purchase_date_uptonow', 'old_category_1__1_count', 'old_authorized_flag__0_fraction', 'new_purchase_amount_max', 'new_weekofyear_mean', 'old_authorized_flag__0_count', 'new_purchase_date_diff', 'old_subsector_id_bins__(11.614, 12.465]_fraction', 'new_weekofyear_max', 'old_merchant_id_bins__(3.091, 4.111]_fraction', 'new_duration_max', 'old_amount_month_ratio_min', 'new_day_mean', 'old_merchant_category_id_bins__(9.368, 10.692]_fraction', 'old_duration_mean', 'old_purchase_date_month_diff_max', 'old_purchase_amount_median', 'old_purchase_date_month_diff_median', 'old_category_1__1_fraction', 'new_month_mean', 'old_Children_day_2017_mean', 'days_feature2', 'old_category_1__0_fraction', 'old_subsector_id_bins__(12.465, 13.476]_fraction', 'days_feature1', 'old_category_3__C_fraction', 'old_day_mean', 'new_amount_month_ratio_max', 'old_purchase_date_month_diff_std', 'old_price_var', 'new_Christmas_Day_2017_mean', 'old_hour_mean', 'old_installments_sum', 'old_subsector_id_bins__(13.476, 15.537]_fraction', 'new_Black_Friday_2017_mean', 'old_purchase_date_month_diff_sum', 'old_month_lag_skew', 'new_duration_mean', 'old_month_lag_mad', 'new_weekofyear_min', 'new_day_max', 'old_merchant_id_bins__(2.197, 3.091]_fraction', 'new_hour_mean', 'old_category_3__B_count', 'old_merchant_category_id_bins__(10.692, 15.53]_fraction', 'old_purchase_date_diff', 'old_weekday_mean', 'old_subsector_id_bins__(12.465, 13.476]_count', 'old_subsector_id_bins__(10.06, 11.614]_fraction', 'old_month_lag_sum', 'old_weekofyear_nunique', 'old_category_3__C_count', 'new_purchase_amount_median', 'days_feature2_ratio', 'old_purchase_date_uptomin', 'old_weekend_mean', 'new_duration_min', 'old_month_lag_std', 'days_feature1_ratio', 'days_feature3', 'old_purchase_date_month_diff_mean', 'new_purchase_amount_mean', 'old_Black_Friday_2017_mean', 'old_category_3__B_fraction', 'new_Children_day_2017_mean', 'old_merchant_id_bins__(1.099, 2.197]_fraction', 'new_purchase_date_uptomin', 'old_purchase_date_month_diff_min', 'new_Mothers_Day_2018_mean', 'old_merchant_category_id_bins__(7.849, 9.368]_fraction', 'old_price_mean', 'old_purchase_amount_skew', 'new_duration_var', 'old_duration_max', 'old_merchant_id_bins__(4.111, 14.042]_fraction', 'new_price_var', 'new_month_lag_std', 'old_category_2__1.0_count', 'old_purchase_amount_mean', 'old_amount_month_ratio_mean', 'new_month_lag_max', 'new_amount_month_ratio_mean', 'old_amount_month_ratio_skew', 'old_installments_std', 'old_city_id_bins__(11.183, 15.391]_fraction', 'old_authorized_flag__1_fraction', 'new_hour_min', 'new_purchase_amount_sum', 'old_category_1__0_count', 'old_city_id_bins__(10.474, 11.183]_fraction', 'new_month_lag_skew', 'new_price_min', 'old_merchant_category_id_bins__(9.368, 10.692]_count', 'old_duration_skew', 'old_Christmas_Day_2017_mean', 'old_city_id_bins__(11.183, 15.391]_count', 'new_amount_month_ratio_var', 'new_amount_month_ratio_min', 'old_category_3__A_fraction', 'old_installments_skew', 'new_day_min', 'old_state_id_bins__(14.065, 16.173]_count', 'old_subsector_id_bins__(11.614, 12.465]_count', 'old_installments_mad', 'new_weekday_mean', 'old_merchant_id_bins__(-0.001, 1.099]_fraction', 'new_subsector_id_bins__(11.111, 12.737]_fraction', 'old_category_2__1.0_fraction', 'old_merchant_id_bins__(3.091, 4.111]_count', 'old_city_id_bins__(9.928, 10.474]_fraction', 'old_amount_month_ratio_max', 'old_purchase_amount_sum', 'elapsed_time', 'old_month_mean', 'old_subsector_id_bins__(4.819, 10.06]_fraction', 'old_weekofyear_max', 'old_weekofyear_min', 'old_month_lag_median', 'old_purchase_amount_mad', 'old_price_max', 'old_weekofyear_mean', 'new_category_3__A_count', 'new_hour_max', 'new_purchase_amount_mad', 'old_category_3__A_count', 'old_amount_month_ratio_var', 'new_purchase_amount_std', 'old_category_2__4.0_fraction', 'old_subsector_id_bins__(13.476, 15.537]_count', 'old_purchase_amount_max', 'new_month_lag_median', 'old_state_id_bins__(13.479, 14.065]_fraction', 'old_subsector_id_bins__(10.06, 11.614]_count', 'old_city_id_bins__(9.441, 9.928]_fraction', 'old_duration_var', 'new_subsector_id_bins__(10.053, 11.111]_fraction', 'old_category_2__5.0_fraction', 'new_purchase_amount_skew', 'old_category_2__4.0_count', 'old_state_id_bins__(14.065, 16.173]_fraction', 'old_city_id_bins__(10.474, 11.183]_count', 'old_category_2__3.0_fraction', 'new_category_3__B_fraction', 'new_price_mean', 'old_city_id_bins__(9.928, 10.474]_count', 'new_merchant_id_bins__(2.079, 10.804]_fraction', 'new_duration_skew', 'new_price_max', 'old_merchant_category_id_bins__(5.533, 7.849]_fraction', 'old_hour_nunique', 'old_Mothers_Day_2018_mean', 'old_state_id_bins__(12.236, 12.862]_fraction', 'old_merchant_id_bins__(2.197, 3.091]_count', 'old_price_min', 'old_purchase_amount_std', 'new_amount_month_ratio_skew', 'old_state_id_bins__(12.862, 13.479]_fraction', 'old_state_id_bins__(8.885, 12.236]_count', 'new_merchant_category_id_bins__(8.485, 12.163]_fraction', 'new_subsector_id_bins__(9.477, 10.053]_fraction', 'old_day_max', 'old_merchant_category_id_bins__(10.692, 15.53]_count', 'old_city_id_bins__(3.806, 9.441]_fraction', 'new_merchant_category_id_bins__(8.485, 12.163]_count', 'old_hour_min', 'old_category_2__2.0_fraction', 'days_feature3_ratio', 'old_state_id_bins__(12.862, 13.479]_count', 'new_merchant_id_bins__(0.693, 1.386]_fraction', 'old_day_nunique', 'old_authorized_flag__1_count', 'new_subsector_id_bins__(11.111, 12.737]_count', 'old_state_id_bins__(13.479, 14.065]_count', 'new_category_2__1.0_count', 'new_installments_std', 'new_month_max', 'new_merchant_category_id_bins__(7.156, 8.485]_fraction', 'new_month_lag_sum', 'old_merchant_id_bins__(4.111, 14.042]_count', 'old_category_2__5.0_count', 'new_category_3__B_count', 'new_month_lag_mean', 'old_state_id_bins__(8.885, 12.236]_fraction', 'new_installments_sum', 'old_category_2__3.0_count', 'new_merchant_id_bins__(2.079, 10.804]_count', 'new_merchant_id_bins__(1.386, 2.079]_fraction', 'new_hist_count', 'new_installments_mad', 'old_merchant_category_id_bins__(7.849, 9.368]_count', 'old_month_lag_mean', 'new_merchant_id_bins__(-0.001, 0.693]_fraction', 'new_installments_skew', 'new_city_id_bins__(8.641, 12.704]_count', 'old_month_lag_max', 'new_installments_median', 'old_merchant_id_bins__(1.099, 2.197]_count', 'new_state_id_bins__(11.433, 13.505]_count', 'old_day_min', 'new_weekday_min', 'new_weekday_max', 'old_state_id_bins__(12.236, 12.862]_count', 'old_installments_max', 'feature_var', 'new_category_2__5.0_fraction', 'old_merchant_category_id_bins__(-0.001, 5.533]_fraction', 'quarter', 'new_month_lag_mad', 'new_category_3__C_fraction', 'new_weekend_mean', 'new_installments_max', 'old_city_id_bins__(9.441, 9.928]_count', 'old_merchant_category_id_bins__(5.533, 7.849]_count', 'old_category_2__2.0_count', 'new_category_2__1.0_fraction', 'new_state_id_bins__(11.433, 13.505]_fraction', 'new_city_id_bins__(8.641, 12.704]_fraction', 'new_weekofyear_nunique', 'new_category_3__A_fraction', 'feature_sum', 'new_installments_mean', 'new_city_id_bins__(7.249, 7.814]_fraction', 'old_hist_count', 'old_hour_max', 'new_subsector_id_bins__(7.706, 9.477]_fraction', 'new_day_nunique', 'new_subsector_id_bins__(10.053, 11.111]_count', 'new_category_2__4.0_fraction', 'old_city_id_bins__(3.806, 9.441]_count', 'new_state_id_bins__(9.474, 10.222]_fraction', 'new_hour_nunique', 'new_merchant_category_id_bins__(5.822, 7.156]_fraction', 'old_subsector_id_bins__(4.819, 10.06]_count', 'new_city_id_bins__(7.814, 8.641]_fraction', 'new_state_id_bins__(10.886, 11.433]_fraction', 'new_merchant_category_id_bins__(3.434, 5.822]_fraction', 'feature1_3', 'new_month_min', 'old_month_min', 'new_city_id_bins__(6.778, 7.249]_fraction', 'new_category_2__4.0_count', 'feature1_1', 'new_merchant_id_bins__(0.693, 1.386]_count', 'old_month_max', 'new_category_2__2.0_fraction', 'new_state_id_bins__(9.474, 10.222]_count', 'old_merchant_id_bins__(-0.001, 1.099]_count', 'new_state_id_bins__(10.886, 11.433]_count', 'new_state_id_bins__(10.222, 10.886]_fraction', 'new_category_2__5.0_count', 'old_installments_median', 'new_category_2__3.0_count', 'new_category_3__C_count', 'feature1_4', 'new_city_id_bins__(7.814, 8.641]_count', 'new_state_id_bins__(5.877, 9.474]_fraction', 'new_merchant_category_id_bins__(7.156, 8.485]_count', 'new_city_id_bins__(6.778, 7.249]_count', 'new_state_id_bins__(10.222, 10.886]_count', 'new_category_2__3.0_fraction', 'feature1_2', 'new_merchant_id_bins__(-0.001, 0.693]_count', 'new_merchant_id_bins__(1.386, 2.079]_count', 'new_category_2__2.0_count', 'new_city_id_bins__(1.608, 6.778]_fraction', 'old_merchant_category_id_bins__(-0.001, 5.533]_count', 'feature_2', 'new_city_id_bins__(7.249, 7.814]_count', 'old_weekday_max', 'feature_1', 'new_merchant_category_id_bins__(-0.001, 3.434]_fraction', 'new_subsector_id_bins__(9.477, 10.053]_count', 'new_state_id_bins__(5.877, 9.474]_count', 'old_weekday_min', 'feature2_2', 'new_subsector_id_bins__(2.0780000000000003, 7.706]_fraction', 'new_subsector_id_bins__(7.706, 9.477]_count', 'new_merchant_category_id_bins__(5.822, 7.156]_count', 'feature_max', 'feature_mean', 'feature_3', 'new_city_id_bins__(1.608, 6.778]_count', 'new_merchant_category_id_bins__(3.434, 5.822]_count', 'old_installments_mean', 'feature2_3', 'feature3_1', 'feature1_5', 'new_subsector_id_bins__(2.0780000000000003, 7.706]_count', 'feature2_1', 'new_merchant_category_id_bins__(-0.001, 3.434]_count', 'feature3_0', 'feature_min']
All_feature_new_extra = ['new_hist_purchase_amount_max', 'hist_month_diff_mean', 'hist_purchase_date_max', 'new_hist_weekofyear_mean', 'hist_authorized_flag_mean_x', 'new_hist_purchase_date_max', 'new_hist_purchase_amount_var', 'new_hist_purchase_date_diff', 'new_hist_purchase_amount_median', 'new_hist_month_lag_mean', 'hist_month_nunique', 'authorized_flag_N', 'new_hist_month_mean', 'new_hist_weekofyear_max', 'month_lag_0', 'subsector_id_x_8', 'hist_purchase_date_average', 'merchant_category_id_x_755', 'new_hist_purchase_date_average', 'hist_purchase_amount_mean', 'new_hist_purchase_date_uptonow', 'hist_purchase_amount_median', 'new_hist_category_1_mean', 'hist_month_lag_mean', 'hist_purchase_date_min', 'category_1_x_Y', 'hist_first_buy', 'new_hist_weekofyear_min', 'hist_last_buy', 'month_lag_1', 'month_lag_-5', 'hist_purchase_amount_var', 'hist_month_lag_var', 'new_hist_purchase_amount_min', 'hist_month_diff_var', 'month_lag_-6', 'hist_category_1_mean', 'hist_month_lag_skew', 'purchase_amount_skew', 'new_hist_weekofyear_median', 'hist_hour_mean', 'hist_dayofweek_mean', 'category_1_y_Y', 'month_lag_-1', 'avg_purchases_lag3_min', 'new_hist_purchase_date_uptomin', 'hist_purchase_date_diff', 'merchant_category_id_x_661', 'hist_installments_mean', 'subsector_id_x_37', 'new_hist_hour_median', 'month_lag_-3', 'hist_purchase_amount_skew', 'hist_installments_var', 'category_3_C', 'hist_year_mean', 'hist_category_1_sum', 'category_4_Y', 'subsector_id_x_7', 'hist_installments_sum', 'hist_merchant_id_nunique', 'new_hist_category_1_sum', 'month_lag_-2', 'new_hist_last_buy', 'hist_category_3_sum', 'purchase_amount_median', 'month_lag_-8', 'new_hist_first_buy', 'hist_weekend_mean', 'purchase_amount_min', 'avg_sales_lag12_min', 'most_recent_sales_range_C', 'month_lag_-7', 'purchase_amount_std', 'numerical_2_skew', 'installments_3', 'subsector_id_x_33', 'most_recent_purchases_range_B', 'merchant_category_id_x_511', 'installments_0', 'hist_weekofyear_nunique', 'installments_2', 'subsector_id_x_29', 'subsector_id_x_34', 'avg_purchases_lag6_min', 'new_hist_purchase_amount_skew', 'merchant_category_id_x_278', 'merchant_category_id_x_451', 'most_recent_purchases_range_D', 'numerical_1_skew', 'avg_sales_lag12_skew', 'merchant_category_id_x_879', 'new_hist_month_diff_mean', 'avg_purchases_lag12_median', 'new_hist_purchase_date_min', 'avg_purchases_lag6_median', 'avg_sales_lag3_min', 'hist_installments_skew', 'city_id_x_69', 'new_hist_month_lag_var', 'avg_purchases_lag3_median', 'month_lag_-9', 'hist_weekofyear_min', 'purchase_amount_total', 'category_2_x_1.0', 'city_id_x_-1', 'hist_category_2_mean_mean', 'subsector_id_x_22', 'category_2_y_1.0', 'avg_purchases_lag3_skew', 'most_recent_sales_range_B', 'most_recent_purchases_range_A', 'most_recent_sales_range_A', 'hist_weekofyear_mean', 'avg_sales_lag3_skew', 'hist_purchase_amount_min', 'most_recent_purchases_range_C', 'subsector_id_x_27', 'new_hist_dayofweek_mean', 'state_id_x_9', 'state_id_x_-1', 'hist_purchase_amount_sum', 'avg_sales_lag6_min', 'most_recent_sales_range_D', 'new_hist_installments_var', 'avg_sales_lag12_median', 'new_hist_category_3_mean_mean', 'category_1_y_N', 'merchant_category_id_x_574', 'avg_sales_lag3_mean', 'hist_merchant_category_id_nunique', 'category_1_x_N', 'hist_month_mean', 'avg_purchases_lag3_mean', 'numerical_2_mean', 'avg_sales_lag6_median', 'most_recent_purchases_range_E', 'hist_month_diff_max', 'hist_weekofyear_max', 'new_hist_month_max', 'subsector_id_x_19', 'avg_sales_lag3_std', 'avg_purchases_lag6_skew', 'avg_sales_lag6_skew', 'avg_sales_lag12_mean', 'weekofyear', 'avg_purchases_lag12_skew', 'feature_1', 'new_hist_hour_max', 'merchant_category_id_x_705', 'avg_purchases_lag12_min', 'avg_purchases_lag3_std', 'merchant_category_id_x_839', 'hist_purchase_date_uptonow', 'elapsed_time', 'merchant_category_id_x_80', 'merchant_category_id_x_683', 'active_months_lag12_7.0', 'avg_purchases_lag12_mean', 'merchant_category_id_x_307', 'new_hist_installments_skew', 'numerical_2_median', 'most_recent_sales_range_E', 'new_hist_month_lag_skew', 'city_id_x_158', 'hist_category_2_sum', 'hist_purchase_date_uptomin', 'numerical_1_median', 'numerical_2_std', 'subsector_id_x_1', 'month_lag_-10', 'month_lag_-11', 'new_hist_installments_mean', 'avg_sales_lag6_mean', 'new_hist_category_2_sum', 'city_id_x_283', 'hist_subsector_id_nunique', 'month_lag_2', 'avg_sales_lag3_median', 'numerical_1_max', 'avg_sales_lag12_std', 'merchant_category_id_x_108', 'numerical_1_mean', 'merchant_category_id_x_560', 'merchant_category_id_x_367', 'avg_purchases_lag6_std', 'subsector_id_x_16', 'subsector_id_x_21', 'hist_category_2_mean', 'merchant_category_id_x_302', 'installments_4', 'merchant_category_id_x_690', 'new_hist_merchant_category_id_nunique', 'subsector_id_x_15', 'hist_hour_median', 'hist_weekend_sum', 'merchant_category_id_x_90', 'avg_sales_lag6_std', 'state_id_x_15', 'installments_12', 'city_id_x_330', 'new_hist_month_min', 'category_2_y_4.0', 'merchant_category_id_x_884', 'numerical_1_std', 'city_id_x_79', 'merchant_category_id_x_68', 'hist_weekofyear_median', 'installments_5', 'merchant_category_id_x_665', 'merchant_category_id_x_210', 'merchant_category_id_x_178', 'hist_authorized_flag_mean_y', 'state_id_x_12', 'dayofyear', 'merchant_category_id_x_414', 'subsector_id_x_25', 'merchant_category_id_x_422', 'state_id_x_16', 'merchant_category_id_x_836', 'feature_2_y', 'city_id_x_195', 'hist_hour_min', 'merchant_category_id_x_217', 'category_2_x_4.0', 'new_hist_category_2_mean_mean', 'avg_purchases_lag12_std', 'hist_hour_nunique', 'authorized_flag_Y', 'merchant_category_id_x_111', 'merchant_category_id_x_360', 'installments_6', 'subsector_id_x_20', 'card_id_total', 'avg_sales_lag3_max', 'hist_month_lag_median', 'merchant_category_id_x_734', 'installments_10', 'city_id_x_138', 'merchant_category_id_x_792', 'subsector_id_x_36', 'new_hist_installments_sum', 'category_2_y_2.0', 'merchant_category_id_x_87', 'city_id_x_308', 'subsector_id_x_30', 'new_hist_weekend_mean', 'city_id_x_116', 'merchant_category_id_x_842', 'subsector_id_x_3', 'city_id_x_337', 'avg_sales_lag12_max', 'state_id_x_22', 'city_id_x_266', 'dayofweek', 'new_hist_month_median', 'subsector_id_x_18', 'subsector_id_x_17', 'category_2_x_5.0', 'month', 'merchant_category_id_x_398', 'merchant_category_id_x_656', 'new_hist_category_3_mean', 'city_id_x_19', 'new_hist_card_id_count', 'city_id_x_149', 'city_id_x_53', 'state_id_x_24', 'merchant_category_id_x_222', 'hist_authorized_flag_sum_x', 'new_hist_dayofweek_median', 'new_hist_subsector_id_nunique', 'new_hist_weekofyear_nunique', 'avg_purchases_lag6_max', 'subsector_id_x_31', 'city_id_x_233', 'month_lag_-12', 'category_2_x_2.0', 'city_id_x_212', 'merchant_category_id_x_650', 'state_id_x_10', 'city_id_x_87', 'city_id_x_213', 'merchant_category_id_x_195', 'city_id_x_3', 'city_id_x_107', 'merchant_category_id_x_273', 'new_hist_hour_nunique', 'merchant_category_id_x_783', 'merchant_category_id_x_598', 'new_hist_dayofweek_max', 'merchant_category_id_x_497', 'state_id_x_19', 'city_id_x_91', 'new_hist_month_lag_max', 'new_hist_dayofweek_min', 'merchant_category_id_x_454', 'avg_purchases_lag3_max', 'avg_purchases_lag12_max', 'city_id_x_267', 'merchant_category_id_x_771', 'city_id_x_88', 'city_id_x_286', 'hist_installments_max', 'merchant_category_id_x_557', 'category_2_y_5.0', 'merchant_category_id_x_19', 'merchant_category_id_x_779', 'avg_sales_lag6_max', 'merchant_category_id_x_373', 'city_id_x_8', 'city_id_x_333', 'state_id_x_4', 'state_id_x_5', 'merchant_category_id_x_184', 'state_id_x_20', 'new_hist_merchant_id_nunique', 'merchant_category_id_x_434', 'merchant_category_id_x_317', 'new_hist_month_diff_median', 'city_id_x_168', 'city_id_x_96', 'new_hist_category_3_min', 'hist_month_diff_min', 'active_months_lag6_6.0', 'city_id_x_137', 'hist_month_diff_median', 'state_id_x_2', 'merchant_category_id_x_45', 'city_id_x_274', 'merchant_category_id_x_834', 'city_id_x_110', 'merchant_category_id_x_550', 'state_id_x_11', 'city_id_x_244', 'subsector_id_x_32', 'state_id_x_3', 'city_id_x_331', 'merchant_category_id_x_427', 'active_months_lag12_12.0', 'hist_card_id_count', 'city_id_x_253', 'merchant_category_id_x_332', 'merchant_category_id_x_206', 'merchant_category_id_x_309', 'city_id_x_322', 'new_hist_installments_max', 'city_id_x_126', 'subsector_id_x_2', 'hist_month_lag_max', 'hist_hour_max', 'city_id_x_277', 'city_id_x_347', 'subsector_id_x_-1', 'city_id_x_296', 'city_id_x_329', 'new_hist_installments_median', 'numerical_2_max', 'state_id_x_21', 'city_id_x_124', 'subsector_id_x_10', 'merchant_category_id_x_556', 'merchant_category_id_x_299', 'hist_dayofweek_median', 'city_id_x_299', 'merchant_category_id_x_38', 'new_hist_category_3_sum', 'city_id_x_179', 'city_id_x_7', 'state_id_x_7', 'subsector_id_x_5', 'city_id_x_117', 'new_hist_year_nunique', 'merchant_category_id_x_818', 'subsector_id_x_38', 'new_hist_installments_min', 'quarter', 'state_id_x_1', 'subsector_id_x_41', 'installments_-1', 'merchant_category_id_x_607', 'hist_month_min', 'hist_month_lag_min', 'merchant_category_id_x_518', 'city_id_x_325', 'subsector_id_x_4', 'hist_month_median', 'city_id_x_20', 'hist_category_2_max', 'city_id_x_1', 'merchant_category_id_x_544', 'city_id_x_291', 'feature_3', 'merchant_category_id_x_819', 'merchant_category_id_x_561', 'merchant_category_id_x_298', 'city_id_x_280', 'city_id_x_182', 'subsector_id_x_35', 'city_id_x_106', 'city_id_x_60', 'state_id_x_14', 'installments_7', 'new_hist_dayofweek_nunique', 'city_id_x_102', 'merchant_category_id_x_130', 'hist_category_3_min', 'merchant_category_id_x_519', 'city_id_x_223', 'merchant_category_id_x_34', 'hist_installments_min', 'merchant_category_id_x_419', 'merchant_category_id_x_290', 'city_id_x_171', 'city_id_x_340', 'city_id_x_38', 'merchant_category_id_x_840', 'hist_month_max', 'state_id_x_13', 'city_id_x_334', 'merchant_category_id_x_387', 'hist_installments_median', 'feature_1_y', 'city_id_x_163', 'city_id_x_125', 'city_id_x_25', 'merchant_category_id_x_369', 'merchant_category_id_x_356', 'merchant_category_id_x_2', 'merchant_category_id_x_706', 'city_id_x_208', 'category_3_A', 'city_id_x_318', 'city_id_x_143', 'city_id_x_216', 'city_id_x_236', 'feature_2_x', 'city_id_x_62', 'city_id_x_250', 'merchant_category_id_x_489', 'city_id_x_14', 'city_id_x_64', 'city_id_x_159', 'city_id_x_100', 'city_id_x_289', 'new_hist_weekend_sum', 'city_id_x_188', 'subsector_id_x_9', 'merchant_category_id_x_384', 'merchant_category_id_x_813', 'city_id_x_4', 'merchant_category_id_x_793', 'city_id_x_12', 'merchant_category_id_x_63', 'city_id_x_21', 'city_id_x_278', 'merchant_category_id_x_554', 'merchant_category_id_x_645', 'city_id_x_199', 'city_id_x_57', 'city_id_x_231', 'merchant_category_id_x_630', 'city_id_x_56', 'merchant_category_id_x_9', 'merchant_category_id_x_781', 'new_hist_category_2_max', 'city_id_x_344', 'city_id_x_242', 'city_id_x_97', 'merchant_category_id_x_411', 'merchant_category_id_x_415', 'city_id_x_200', 'merchant_category_id_x_14', 'merchant_category_id_x_491', 'city_id_x_198', 'hist_dayofweek_nunique', 'city_id_x_80', 'merchant_category_id_x_110', 'city_id_x_52', 'merchant_category_id_x_412', 'merchant_category_id_x_769', 'merchant_category_id_x_527', 'month_lag_-13', 'state_id_x_18', 'subsector_id_x_12', 'city_id_x_51', 'state_id_x_8', 'numerical_1_min', 'merchant_category_id_x_241', 'city_id_x_262', 'city_id_x_36', 'city_id_x_42', 'merchant_category_id_x_246', 'new_hist_month_diff_max', 'city_id_x_281', 'subsector_id_x_26', 'merchant_category_id_x_330', 'merchant_category_id_x_385', 'city_id_x_94', 'city_id_x_75', 'active_months_lag12_9.0', 'merchant_category_id_x_198', 'city_id_x_218', 'city_id_x_147', 'merchant_category_id_x_105', 'state_id_x_17', 'merchant_category_id_x_763', 'installments_8', 'city_id_x_90', 'merchant_category_id_x_171', 'city_id_x_209', 'city_id_x_140', 'city_id_x_160', 'merchant_category_id_x_774', 'city_id_x_341', 'merchant_category_id_x_259', 'city_id_x_271', 'city_id_x_304', 'active_months_lag3_3.0', 'merchant_category_id_x_667', 'merchant_category_id_x_248', 'merchant_category_id_x_181', 'new_hist_category_1_median', 'city_id_x_339', 'merchant_category_id_x_333', 'merchant_category_id_x_56', 'city_id_x_270', 'city_id_x_260', 'merchant_category_id_x_692', 'state_id_x_23', 'merchant_category_id_x_363', 'city_id_x_328', 'city_id_x_66', 'merchant_category_id_x_33', 'merchant_category_id_x_478', 'new_hist_month_diff_min', 'city_id_x_34', 'active_months_lag12_5.0', 'city_id_x_47', 'city_id_x_323', 'city_id_x_10', 'city_id_x_2', 'city_id_x_161', 'merchant_category_id_x_528', 'merchant_category_id_x_40', 'city_id_x_272', 'city_id_x_170', 'city_id_x_279', 'city_id_x_248', 'merchant_category_id_x_795', 'merchant_category_id_x_637', 'merchant_category_id_x_319', 'subsector_id_x_23', 'city_id_x_155', 'new_hist_category_2_min', 'merchant_category_id_x_209', 'city_id_x_78', 'merchant_category_id_x_531', 'city_id_x_239', 'merchant_category_id_x_748', 'merchant_category_id_x_546', 'city_id_x_251', 'city_id_x_206', 'city_id_x_151', 'merchant_category_id_x_409', 'merchant_category_id_x_703', 'merchant_category_id_x_383', 'city_id_x_180', 'city_id_x_76', 'city_id_x_101', 'city_id_x_238', 'city_id_x_26', 'city_id_x_288', 'active_months_lag12_3.0', 'active_months_lag12_6.0', 'city_id_x_40', 'city_id_x_46', 'merchant_category_id_x_568', 'merchant_category_id_x_529', 'city_id_x_85', 'merchant_category_id_x_391', 'city_id_x_258', 'merchant_category_id_x_438', 'city_id_x_302', 'city_id_x_292', 'city_id_x_30', 'merchant_category_id_x_166', 'merchant_category_id_x_695', 'city_id_x_230', 'merchant_category_id_x_631', 'merchant_category_id_x_480', 'city_id_x_35', 'merchant_category_id_x_60', 'city_id_x_190', 'active_months_lag12_11.0', 'merchant_category_id_x_605', 'merchant_category_id_x_443', 'merchant_category_id_x_670', 'city_id_x_326', 'hist_category_2_min', 'city_id_x_48', 'city_id_x_303', 'new_hist_month_lag_median', 'merchant_category_id_x_416', 'active_months_lag6_4.0', 'city_id_x_247', 'merchant_category_id_x_651', 'city_id_x_11', 'city_id_x_135', 'merchant_category_id_x_462', 'city_id_x_123', 'merchant_category_id_x_320', 'city_id_x_24', 'merchant_category_id_x_437', 'city_id_x_285', 'merchant_category_id_x_289', 'city_id_x_345', 'city_id_x_214', 'merchant_category_id_x_623', 'merchant_category_id_x_668', 'city_id_x_113', 'merchant_category_id_x_881', 'merchant_category_id_x_126', 'merchant_category_id_x_81', 'city_id_x_184', 'city_id_x_194', 'city_id_x_221', 'city_id_x_224', 'city_id_x_227', 'city_id_x_17', 'merchant_category_id_x_267', 'city_id_x_82', 'city_id_x_33', 'merchant_category_id_x_215', 'active_months_lag12_8.0', 'city_id_x_29', 'city_id_x_39', 'city_id_x_311', 'merchant_category_id_x_472', 'city_id_x_327', 'subsector_id_x_39', 'active_months_lag3_2.0', 'merchant_category_id_x_642', 'merchant_category_id_x_761', 'numerical_2_min', 'merchant_category_id_x_357', 'merchant_category_id_x_823', 'merchant_category_id_x_-1', 'merchant_category_id_x_458', 'merchant_category_id_x_396', 'merchant_category_id_x_312', 'installments_9', 'merchant_category_id_x_506', 'new_hist_month_lag_min', 'merchant_category_id_x_69', 'merchant_category_id_x_420', 'city_id_x_13', 'city_id_x_191', 'city_id_x_54', 'city_id_x_9', 'merchant_category_id_x_340', 'city_id_x_268', 'city_id_x_162', 'city_id_x_187', 'merchant_category_id_x_78', 'city_id_x_246', 'merchant_category_id_x_274', 'city_id_x_234', 'installments_11', 'city_id_x_23', 'city_id_x_109', 'hist_authorized_flag_sum_y', 'city_id_x_115', 'city_id_x_130', 'city_id_x_103', 'city_id_x_136', 'merchant_category_id_x_671', 'city_id_x_294', 'merchant_category_id_x_386', 'city_id_x_256', 'merchant_category_id_x_180', 'merchant_category_id_x_57', 'city_id_x_297', 'city_id_x_314', 'merchant_category_id_x_591', 'city_id_x_169', 'city_id_x_150', 'city_id_x_173', 'hist_dayofweek_min', 'city_id_x_245', 'city_id_x_219', 'merchant_category_id_x_342', 'new_hist_month_nunique', 'city_id_x_282', 'subsector_id_x_40', 'merchant_category_id_x_216', 'merchant_category_id_x_154', 'feature_1_x', 'new_hist_card_id_size', 'merchant_category_id_x_432', 'city_id_x_189', 'city_id_x_74', 'merchant_category_id_x_225', 'merchant_category_id_x_614', 'city_id_x_131', 'city_id_x_146', 'hist_year_nunique', 'city_id_x_174', 'city_id_x_71', 'city_id_x_300', 'hist_card_id_size', 'merchant_category_id_x_114', 'merchant_category_id_x_843', 'city_id_x_16', 'merchant_category_id_x_891', 'subsector_id_x_14', 'city_id_x_232', 'merchant_category_id_x_702', 'new_hist_year_mean', 'hist_category_1_median', 'merchant_category_id_x_885', 'hist_dayofweek_max', 'city_id_x_298', 'city_id_x_22', 'merchant_category_id_x_119', 'merchant_category_id_x_224', 'city_id_x_32', 'city_id_x_63', 'feature_2', 'merchant_category_id_x_53', 'merchant_category_id_x_737', 'city_id_x_275', 'feature_3_y', 'city_id_x_193', 'city_id_x_295', 'city_id_x_335', 'city_id_x_156', 'city_id_x_235', 'merchant_category_id_x_179', 'city_id_x_157', 'city_id_x_269', 'merchant_category_id_x_400', 'merchant_category_id_x_292', 'city_id_x_142', 'city_id_x_120', 'city_id_x_264', 'city_id_x_205', 'city_id_x_144', 'merchant_category_id_x_499', 'city_id_x_259', 'new_hist_category_1_min', 'city_id_x_18', 'city_id_x_342', 'city_id_x_61', 'active_months_lag12_4.0', 'city_id_x_166', 'city_id_x_276', 'merchant_category_id_x_829', 'city_id_x_201', 'merchant_category_id_x_534', 'merchant_category_id_x_514', 'city_id_x_252', 'merchant_category_id_x_474', 'merchant_category_id_x_374', 'city_id_x_226', 'state_id_x_6', 'merchant_category_id_x_315', 'merchant_category_id_x_593', 'city_id_x_204', 'city_id_x_98', 'merchant_category_id_x_713', 'new_hist_weekend_median', 'merchant_category_id_x_71', 'city_id_x_119', 'merchant_category_id_x_827', 'merchant_category_id_x_21', 'city_id_x_139', 'merchant_category_id_x_172', 'city_id_x_108', 'city_id_x_73', 'hist_category_1_max', 'merchant_category_id_x_117', 'city_id_x_336', 'merchant_category_id_x_16', 'city_id_x_301', 'merchant_category_id_x_806', 'merchant_category_id_x_796', 'merchant_category_id_x_751', 'merchant_category_id_x_247', 'city_id_x_41', 'subsector_id_x_13', 'merchant_category_id_x_417', 'merchant_category_id_x_265', 'city_id_x_172', 'city_id_x_133', 'merchant_category_id_x_669', 'city_id_x_210', 'city_id_x_263', 'city_id_x_312', 'city_id_x_320', 'active_months_lag6_5.0', 'active_months_lag6_3.0', 'city_id_x_254', 'city_id_x_167', 'merchant_category_id_x_696', 'merchant_category_id_x_157', 'merchant_category_id_x_717', 'merchant_category_id_x_507', 'new_hist_category_1_max', 'active_months_lag6_2.0', 'new_hist_year_median', 'merchant_category_id_x_430', 'city_id_x_153', 'city_id_x_148', 'merchant_category_id_x_573', 'city_id_x_181', 'city_id_x_118', 'merchant_category_id_x_854', 'city_id_x_70', 'city_id_x_261', 'city_id_x_321', 'city_id_x_307', 'city_id_x_293', 'city_id_x_111', 'subsector_id_x_24', 'city_id_x_290', 'hist_weekend_median', 'merchant_category_id_x_348', 'merchant_category_id_x_36', 'hist_category_1_min', 'city_id_x_338', 'city_id_x_240', 'merchant_category_id_x_873', 'merchant_category_id_x_276', 'city_id_x_6', 'city_id_x_211', 'city_id_x_81', 'feature_3_x', 'subsector_id_x_11', 'city_id_x_68', 'city_id_x_44', 'merchant_category_id_x_504', 'city_id_x_310', 'merchant_category_id_x_613', 'city_id_x_86', 'city_id_x_287', 'city_id_x_229', 'merchant_category_id_x_182', 'merchant_category_id_x_456', 'city_id_x_265', 'merchant_category_id_x_808', 'city_id_x_183', 'city_id_x_228', 'new_hist_year_max', 'city_id_x_255', 'city_id_x_343', 'merchant_category_id_x_471', 'merchant_category_id_x_469', 'city_id_x_104', 'merchant_category_id_x_162', 'merchant_category_id_x_889', 'merchant_category_id_x_687', 'merchant_category_id_x_686', 'city_id_x_105', 'merchant_category_id_x_685', 'merchant_category_id_x_131', 'city_id_x_114', 'city_id_x_89', 'merchant_category_id_x_676', 'active_months_lag12_2.0', 'merchant_category_id_x_183', 'merchant_category_id_x_140', 'new_hist_category_3_max', 'merchant_category_id_x_882', 'city_id_x_65', 'subsector_id_x_28', 'city_id_x_112', 'merchant_category_id_x_67', 'merchant_category_id_x_145', 'merchant_category_id_x_18', 'merchant_category_id_x_141', 'city_id_x_84', 'new_hist_weekend_min', 'merchant_category_id_x_817', 'merchant_category_id_x_814', 'merchant_category_id_x_83', 'new_hist_year_min', 'merchant_category_id_x_805', 'merchant_category_id_x_803', 'city_id_x_77', 'new_hist_weekend_max', 'merchant_category_id_x_847', 'city_id_x_83', 'merchant_category_id_x_153', 'merchant_category_id_x_741', 'merchant_category_id_x_86', 'merchant_category_id_x_725', 'merchant_category_id_x_718', 'merchant_category_id_x_714', 'merchant_category_id_x_875', 'active_months_lag6_1.0', 'merchant_category_id_x_712', 'merchant_category_id_x_164', 'active_months_lag3_1.0', 'merchant_category_id_x_878', 'hist_category_3_max', 'merchant_category_id_x_187', 'city_id_x_165', 'merchant_category_id_x_664', 'merchant_category_id_x_27', 'hist_year_median', 'merchant_category_id_x_311', 'merchant_category_id_x_31', 'hist_year_max', 'hist_weekend_min', 'merchant_category_id_x_464', 'city_id_x_237', 'merchant_category_id_x_281', 'merchant_category_id_x_482', 'merchant_category_id_x_49', 'merchant_category_id_x_662', 'city_id_x_222', 'city_id_x_220', 'merchant_category_id_x_268', 'merchant_category_id_x_498', 'city_id_x_92', 'merchant_category_id_x_266', 'merchant_category_id_x_509', 'merchant_category_id_x_513', 'city_id_x_207', 'merchant_category_id_x_457', 'merchant_category_id_x_448', 'hist_year_min', 'merchant_category_id_x_436', 'merchant_category_id_x_343', 'merchant_category_id_x_322', 'city_id_x_306', 'merchant_category_id_x_345', 'merchant_category_id_x_351', 'city_id_x_309', 'merchant_category_id_x_355', 'merchant_category_id_x_358', 'city_id_x_313', 'merchant_category_id_x_37', 'city_id_x_28', 'merchant_category_id_x_381', 'city_id_x_315', 'merchant_category_id_x_393', 'city_id_x_316', 'city_id_x_273', 'merchant_category_id_x_401', 'city_id_x_319', 'merchant_category_id_x_421', 'city_id_x_203', 'merchant_category_id_x_52', 'merchant_category_id_x_523', 'merchant_category_id_x_599', 'merchant_category_id_x_603', 'merchant_category_id_x_220', 'city_id_x_49', 'city_id_x_145', 'hist_authorized_flag_max', 'merchant_category_id_x_628', 'merchant_category_id_x_634', 'merchant_category_id_x_648', 'merchant_category_id_x_201', 'merchant_category_id_x_192', 'merchant_category_id_x_190', 'city_id_x_58', 'city_id_x_129', 'city_id_x_128', 'hist_weekend_max', 'merchant_category_id_x_652', 'merchant_category_id_x_653', 'hist_authorized_flag_min', 'city_id_x_122', 'merchant_category_id_x_601', 'merchant_category_id_x_223', 'merchant_category_id_x_526', 'merchant_category_id_x_59', 'merchant_category_id_x_530', 'city_id_x_197', 'merchant_category_id_x_261', 'merchant_category_id_x_536', 'merchant_category_id_x_542', 'merchant_category_id_x_551', 'city_id_x_186', 'city_id_x_185', 'merchant_category_id_x_260', 'merchant_category_id_x_249', 'merchant_category_id_x_579', 'city_id_x_178', 'city_id_x_175', 'merchant_category_id_x_245', 'merchant_category_id_x_580', 'merchant_category_id_x_583', 'merchant_category_id_x_226', 'merchant_category_id_x_587', 'merchant_category_id_x_334', 'city_id_x_215']
weight_DNN =(1 - mae_val_DNN)/(3 - mae_val_DNN - mae_val_RF - mae_val_lgb)
 weight_RF =(1 - mae_val_RF)/(3 - mae_val_DNN - mae_val_RF - mae_val_lgb)
 weight_lgb =(1 - mae_val_lgb)/(3 - mae_val_DNN - mae_val_RF - mae_val_lgb)
 df_test['winPlacePerc'] = df_test.apply(lambda x: x['winPlacePerc_RF'] * weight_RF + x['winPlacePerc_DNN'] * weight_DNN + x['winPlacePerc_lgb'] * weight_lgb, axis=1)
 submission = df_test[['Id', 'winPlacePerc']]
submission.to_csv('submission.csv', index=False )<import_modules>
features_current_model = ['old_duration_min', 'new_purchase_amount_max', 'new_duration_max', 'hist_month_diff_mean', 'new_hist_month_lag_mean', 'hist_month_nunique', 'new_hist_weekofyear_max', 'new_hist_weekofyear_mean', 'new_Christmas_Day_2017_mean', 'new_day_mean', 'new_purchase_date_uptonow', 'new_hist_purchase_date_diff', 'old_authorized_flag__0_fraction', 'merchant_category_id_x_755', 'new_Black_Friday_2017_mean', 'new_amount_month_ratio_max', 'new_hist_category_1_mean', 'days_feature2', 'subsector_id_x_8', 'new_weekofyear_min', 'hist_purchase_date_uptonow', 'month_lag_0', 'old_amount_month_ratio_min', 'new_month_mean', 'month_lag_1', 'old_merchant_category_id_bins__(9.368, 10.692]_fraction', 'new_hist_purchase_date_average', 'category_1_x_Y', 'new_Children_day_2017_mean', 'new_hist_weekofyear_median', 'old_price_var', 'old_purchase_amount_median', 'new_day_max', 'hist_purchase_date_max', 'old_subsector_id_bins__(11.614, 12.465]_fraction', 'merchant_category_id_x_661', 'old_Children_day_2017_mean', 'old_merchant_id_bins__(3.091, 4.111]_fraction', 'new_hist_category_1_sum', 'new_amount_month_ratio_mean', 'authorized_flag_N', 'old_purchase_date_month_diff_std', 'days_feature1', 'new_duration_min', 'new_duration_var', 'new_purchase_amount_median', 'hist_purchase_amount_mean', 'old_category_1__0_fraction', 'old_purchase_date_month_diff_max', 'hist_month_lag_mean', 'old_category_3__C_fraction', 'month_lag_-5', 'old_purchase_date_month_diff_median', 'month_lag_-6', 'old_authorized_flag__0_count', 'merchant_category_id_x_451', 'hist_category_1_sum', 'hist_merchant_id_nunique', 'new_Mothers_Day_2018_mean', 'new_hist_hour_median', 'month_lag_-8', 'category_1_y_Y', 'merchant_category_id_x_511', 'subsector_id_x_37', 'hist_purchase_date_min', 'month_lag_-3', 'hist_first_buy', 'old_day_mean', 'month_lag_-1', 'hist_authorized_flag_mean_y', 'old_category_3__B_fraction', 'old_subsector_id_bins__(10.06, 11.614]_fraction', 'new_hist_purchase_amount_var', 'days_feature3', 'hist_last_buy', 'subsector_id_x_7', 'days_feature1_ratio', 'old_subsector_id_bins__(13.476, 15.537]_fraction', 'old_subsector_id_bins__(12.465, 13.476]_fraction', 'avg_purchases_lag3_min', 'avg_sales_lag12_min', 'new_amount_month_ratio_var', 'old_hour_mean', 'new_price_var', 'hist_month_lag_skew', 'hist_dayofweek_mean', 'old_subsector_id_bins__(12.465, 13.476]_count', 'old_amount_month_ratio_var', 'merchant_category_id_x_879', 'month_lag_-2', 'new_day_min', 'old_month_lag_mad', 'days_feature2_ratio', 'old_Black_Friday_2017_mean', 'new_category_3__A_count', 'hist_month_diff_var', 'hist_category_3_sum', 'old_weekofyear_min', 'old_amount_month_ratio_mean', 'new_hist_last_buy', 'category_4_Y', 'merchant_category_id_x_278', 'hist_purchase_date_average', 'new_amount_month_ratio_min', 'purchase_amount_skew', 'new_hist_purchase_amount_min', 'installments_3', 'month_lag_-9', 'installments_2', 'merchant_category_id_x_705', 'hist_installments_mean', 'hist_year_mean', 'old_duration_var', 'subsector_id_x_22', 'hist_installments_sum', 'old_purchase_date_month_diff_sum', 'purchase_amount_median', 'merchant_category_id_x_574', 'old_weekend_mean', 'old_merchant_id_bins__(1.099, 2.197]_fraction', 'hist_weekofyear_nunique', 'new_hist_purchase_date_uptomin', 'avg_sales_lag3_min', 'hist_category_1_mean', 'old_category_3__C_count', 'most_recent_sales_range_C', 'city_id_x_69', 'new_price_min', 'month_lag_-7', 'old_month_lag_std', 'subsector_id_x_29', 'old_merchant_category_id_bins__(7.849, 9.368]_fraction', 'old_purchase_date_uptomin', 'hist_merchant_category_id_nunique', 'purchase_amount_min', 'city_id_x_283', 'avg_sales_lag6_min', 'old_purchase_amount_mad', 'new_hist_month_diff_mean', 'state_id_x_-1', 'new_hist_purchase_date_max', 'new_hour_max', 'old_month_lag_sum', 'merchant_category_id_x_839', 'numerical_2_skew', 'numerical_1_skew', 'merchant_category_id_x_217', 'subsector_id_x_34', 'old_merchant_category_id_bins__(9.368, 10.692]_count', 'old_purchase_date_month_diff_min', 'old_merchant_id_bins__(4.111, 14.042]_fraction', 'purchase_amount_total', 'state_id_x_9', 'avg_purchases_lag6_min', 'old_subsector_id_bins__(4.819, 10.06]_fraction', 'old_Christmas_Day_2017_mean', 'hist_purchase_amount_skew', 'old_city_id_bins__(10.474, 11.183]_fraction', 'hist_month_diff_max', 'most_recent_sales_range_B', 'subsector_id_x_27', 'category_2_y_1.0', 'old_city_id_bins__(9.928, 10.474]_fraction', 'merchant_category_id_x_90', 'city_id_x_158', 'most_recent_purchases_range_B', 'new_hist_dayofweek_mean', 'avg_sales_lag12_median', 'old_city_id_bins__(11.183, 15.391]_fraction', 'category_3_C', 'old_purchase_date_month_diff_mean', 'subsector_id_x_33', 'avg_sales_lag6_median', 'active_months_lag12_7.0', 'merchant_category_id_x_302', 'merchant_category_id_x_665', 'new_hist_month_lag_skew', 'new_hist_month_lag_var', 'old_merchant_id_bins__(-0.001, 1.099]_fraction', 'old_amount_month_ratio_skew', 'most_recent_sales_range_A', 'avg_purchases_lag3_median', 'old_duration_skew', 'most_recent_purchases_range_D', 'new_subsector_id_bins__(11.111, 12.737]_fraction', 'city_id_x_330', 'hist_weekofyear_max', 'old_purchase_amount_std', 'numerical_2_median', 'merchant_category_id_x_836', 'most_recent_purchases_range_C', 'hist_purchase_date_diff', 'old_merchant_category_id_bins__(5.533, 7.849]_fraction', 'old_merchant_category_id_bins__(-0.001, 5.533]_fraction', 'old_category_1__1_fraction', 'most_recent_sales_range_D', 'old_purchase_amount_sum', 'dayofyear', 'numerical_1_mean', 'avg_purchases_lag3_skew', 'most_recent_purchases_range_A', 'purchase_amount_std', 'avg_purchases_lag6_median', 'merchant_category_id_x_683', 'old_category_2__4.0_fraction', 'installments_4', 'hist_installments_var', 'new_price_max', 'hist_purchase_amount_min', 'category_2_x_1.0', 'old_subsector_id_bins__(11.614, 12.465]_count', 'avg_purchases_lag12_median', 'city_id_x_79', 'avg_sales_lag12_skew', 'city_id_x_-1', 'category_1_y_N', 'avg_purchases_lag3_mean', 'avg_sales_lag3_skew', 'city_id_x_337', 'city_id_x_195', 'new_hist_month_max', 'weekofyear', 'old_merchant_id_bins__(3.091, 4.111]_count', 'state_id_x_12', 'old_city_id_bins__(9.441, 9.928]_fraction', 'avg_sales_lag3_mean', 'merchant_category_id_x_734', 'old_subsector_id_bins__(10.06, 11.614]_count', 'installments_0', 'avg_purchases_lag3_std', 'old_category_3__A_count', 'old_category_2__1.0_fraction', 'category_1_x_N', 'new_hist_installments_var', 'month_lag_-10', 'old_installments_mad', 'old_weekofyear_mean', 'new_purchase_amount_skew', 'old_state_id_bins__(13.479, 14.065]_fraction', 'new_hist_first_buy', 'avg_sales_lag3_median', 'avg_purchases_lag12_min', 'old_month_mean', 'installments_12', 'merchant_category_id_x_307', 'new_hist_category_3_mean_mean', 'city_id_x_53', 'merchant_category_id_x_414', 'merchant_category_id_x_80', 'avg_sales_lag6_skew', 'city_id_x_266', 'numerical_2_std', 'merchant_category_id_x_398', 'avg_purchases_lag12_mean', 'new_category_3__B_fraction', 'avg_purchases_lag12_skew', 'new_hist_purchase_amount_max', 'old_Mothers_Day_2018_mean', 'numerical_1_max', 'city_id_x_308', 'city_id_x_116', 'old_state_id_bins__(12.862, 13.479]_fraction', 'state_id_x_24', 'most_recent_sales_range_E', 'old_city_id_bins__(11.183, 15.391]_count', 'hist_category_2_mean_mean', 'most_recent_purchases_range_E', 'numerical_1_median', 'new_hist_installments_mean', 'old_category_2__1.0_count', 'merchant_category_id_x_178', 'city_id_x_87', 'city_id_x_267', 'month_lag_-11', 'merchant_category_id_x_560', 'merchant_category_id_x_108', 'new_merchant_category_id_bins__(8.485, 12.163]_fraction', 'hist_month_diff_median', 'subsector_id_x_19', 'avg_sales_lag3_std', 'merchant_category_id_x_210', 'avg_sales_lag12_mean', 'city_id_x_91', 'old_city_id_bins__(9.928, 10.474]_count', 'new_subsector_id_bins__(10.053, 11.111]_fraction', 'new_purchase_date_uptomin', 'old_state_id_bins__(12.236, 12.862]_fraction', 'old_state_id_bins__(8.885, 12.236]_fraction', 'avg_sales_lag12_std', 'avg_purchases_lag6_skew', 'old_city_id_bins__(10.474, 11.183]_count', 'old_state_id_bins__(14.065, 16.173]_count', 'hist_subsector_id_nunique', 'new_merchant_id_bins__(2.079, 10.804]_fraction', 'hist_category_2_sum', 'city_id_x_149', 'hist_hour_median', 'merchant_category_id_x_792', 'old_state_id_bins__(8.885, 12.236]_count', 'old_category_2__5.0_fraction', 'old_state_id_bins__(12.862, 13.479]_count', 'subsector_id_x_21', 'state_id_x_15', 'month_lag_2', 'new_month_lag_max', 'subsector_id_x_16', 'merchant_category_id_x_650', 'avg_sales_lag6_mean', 'merchant_category_id_x_184', 'old_category_2__2.0_fraction', 'subsector_id_x_1', 'city_id_x_138', 'old_city_id_bins__(3.806, 9.441]_fraction', 'new_hist_category_2_sum', 'new_category_3__B_count', 'merchant_category_id_x_68', 'merchant_category_id_x_656', 'old_purchase_date_uptonow', 'merchant_category_id_x_111', 'installments_5', 'city_id_x_96', 'old_price_min', 'new_purchase_date_diff', 'avg_sales_lag6_std', 'city_id_x_286', 'state_id_x_22', 'new_merchant_id_bins__(0.693, 1.386]_fraction', 'old_month_lag_median', 'subsector_id_x_15', 'new_amount_month_ratio_skew', 'hist_installments_skew', 'old_installments_std', 'city_id_x_233', 'old_installments_sum', 'state_id_x_10', 'merchant_category_id_x_422', 'new_subsector_id_bins__(11.111, 12.737]_count', 'city_id_x_253', 'category_2_y_4.0', 'new_duration_skew', 'new_subsector_id_bins__(9.477, 10.053]_fraction', 'new_hist_month_median', 'city_id_x_88', 'merchant_category_id_x_690', 'new_merchant_id_bins__(-0.001, 0.693]_fraction', 'new_hist_merchant_category_id_nunique', 'old_subsector_id_bins__(13.476, 15.537]_count', 'city_id_x_110', 'new_month_lag_sum', 'state_id_x_16', 'old_merchant_category_id_bins__(5.533, 7.849]_count', 'hist_weekend_sum', 'new_weekofyear_mean', 'merchant_category_id_x_497', 'avg_purchases_lag12_std', 'merchant_category_id_x_598', 'installments_6', 'city_id_x_3', 'city_id_x_274', 'subsector_id_x_3', 'city_id_x_19', 'subsector_id_x_30', 'merchant_category_id_x_367', 'old_installments_skew', 'old_category_1__0_count', 'hist_weekofyear_median', 'city_id_x_107', 'merchant_category_id_x_454', 'new_installments_median', 'city_id_x_212', 'merchant_category_id_x_273', 'city_id_x_8', 'merchant_category_id_x_771', 'old_state_id_bins__(14.065, 16.173]_fraction', 'hist_hour_min', 'new_hist_purchase_date_uptonow', 'merchant_category_id_x_360', 'merchant_category_id_x_222', 'subsector_id_x_25', 'month_lag_-12', 'merchant_category_id_x_87', 'subsector_id_x_17', 'subsector_id_x_36', 'category_2_y_2.0', 'city_id_x_213', 'merchant_category_id_x_842', 'new_hist_installments_skew', 'old_category_1__1_count', 'merchant_category_id_x_884', 'installments_10', 'avg_sales_lag12_max', 'numerical_2_mean', 'avg_purchases_lag6_max', 'days_feature3_ratio', 'new_weekofyear_max', 'subsector_id_x_31', 'old_hour_nunique', 'old_category_2__4.0_count', 'subsector_id_x_20', 'new_installments_mad', 'new_installments_skew', 'old_day_max', 'old_day_min', 'merchant_category_id_x_779', 'city_id_x_126', 'old_merchant_category_id_bins__(10.692, 15.53]_count', 'new_hist_month_min', 'merchant_category_id_x_206', 'city_id_x_137', 'new_merchant_id_bins__(1.386, 2.079]_fraction', 'merchant_category_id_x_427', 'numerical_1_std', 'city_id_x_168', 'new_hist_dayofweek_median', 'city_id_x_331', 'avg_sales_lag3_max', 'authorized_flag_Y', 'old_merchant_category_id_bins__(7.849, 9.368]_count', 'new_installments_std', 'new_merchant_id_bins__(2.079, 10.804]_count', 'new_month_lag_mad', 'state_id_x_20', 'old_day_nunique', 'feature1_3', 'hist_month_diff_min', 'city_id_x_333', 'state_id_x_4', 'new_hist_purchase_date_min', 'dayofweek', 'new_merchant_category_id_bins__(3.434, 5.822]_fraction', 'subsector_id_x_18', 'old_state_id_bins__(13.479, 14.065]_count', 'old_city_id_bins__(9.441, 9.928]_count', 'merchant_category_id_x_550', 'feature_var', 'new_merchant_category_id_bins__(7.156, 8.485]_fraction', 'old_merchant_id_bins__(1.099, 2.197]_count', 'elapsed_time', 'state_id_x_19', 'avg_purchases_lag6_std', 'new_weekday_min', 'old_state_id_bins__(12.236, 12.862]_count', 'new_category_3__A_fraction', 'hist_purchase_amount_median', 'new_hist_category_2_mean_mean', 'state_id_x_2', 'new_category_2__4.0_count', 'new_installments_mean', 'new_category_2__1.0_count', 'new_merchant_category_id_bins__(8.485, 12.163]_count', 'card_id_total', 'new_hist_month_mean', 'new_city_id_bins__(8.641, 12.704]_fraction', 'feature1_1', 'merchant_category_id_x_309', 'new_hist_purchase_amount_median', 'avg_purchases_lag3_max', 'merchant_category_id_x_834', 'city_id_x_322', 'city_id_x_244', 'merchant_category_id_x_434', 'merchant_category_id_x_557', 'merchant_category_id_x_19', 'merchant_category_id_x_373', 'old_month_lag_max', 'feature_sum', 'merchant_category_id_x_195', 'old_city_id_bins__(3.806, 9.441]_count', 'merchant_category_id_x_783', 'avg_sales_lag6_max', 'merchant_category_id_x_45', 'new_city_id_bins__(8.641, 12.704]_count', 'new_hist_dayofweek_max', 'category_2_x_4.0', 'old_month_lag_skew', 'avg_purchases_lag12_max', 'old_merchant_id_bins__(4.111, 14.042]_count', 'state_id_x_5', 'new_state_id_bins__(11.433, 13.505]_fraction', 'merchant_category_id_x_317', 'new_hist_weekofyear_nunique', 'new_hist_weekofyear_min', 'old_category_2__2.0_count', 'new_category_3__C_fraction', 'merchant_category_id_x_332', 'new_weekend_mean', 'new_category_2__5.0_fraction', 'hist_category_2_mean', 'new_hist_hour_nunique', 'state_id_x_3', 'new_category_2__2.0_fraction', 'state_id_x_11', 'hist_purchase_date_uptomin', 'new_city_id_bins__(7.814, 8.641]_fraction', 'new_merchant_category_id_bins__(5.822, 7.156]_fraction', 'new_city_id_bins__(7.249, 7.814]_fraction', 'new_hist_installments_max', 'hist_installments_max', 'new_state_id_bins__(11.433, 13.505]_count', 'new_subsector_id_bins__(7.706, 9.477]_fraction', 'old_category_2__5.0_count', 'new_state_id_bins__(9.474, 10.222]_fraction', 'new_hist_card_id_count', 'subsector_id_x_2', 'category_2_y_5.0', 'new_category_2__4.0_fraction', 'new_hist_subsector_id_nunique', 'new_hist_category_3_mean', 'new_state_id_bins__(10.886, 11.433]_fraction', 'old_authorized_flag__1_count', 'new_installments_sum', 'old_subsector_id_bins__(4.819, 10.06]_count', 'hist_authorized_flag_mean_x', 'new_category_2__1.0_fraction', 'old_hour_max', 'category_2_x_2.0', 'new_day_nunique', 'subsector_id_x_32', 'old_merchant_id_bins__(-0.001, 1.099]_count', 'hist_month_lag_var', 'new_hist_merchant_id_nunique', 'new_hist_installments_sum', 'old_weekday_mean', 'new_month_lag_skew', 'new_state_id_bins__(9.474, 10.222]_count', 'hist_hour_mean', 'category_2_x_5.0', 'new_city_id_bins__(6.778, 7.249]_fraction', 'new_purchase_amount_std', 'new_subsector_id_bins__(10.053, 11.111]_count', 'new_month_lag_std', 'old_month_lag_mean', 'new_merchant_id_bins__(0.693, 1.386]_count', 'hist_weekend_mean', 'active_months_lag6_6.0', 'active_months_lag12_12.0', 'new_purchase_amount_mean', 'hist_weekofyear_min', 'old_month_min', 'feature_1', 'old_weekofyear_nunique', 'old_purchase_amount_skew', 'new_month_lag_median', 'new_weekday_mean', 'new_installments_max', 'old_weekofyear_max', 'new_state_id_bins__(10.886, 11.433]_count', 'old_month_max', 'old_hist_count', 'hist_purchase_amount_var', 'hist_purchase_amount_sum', 'hist_month_mean', 'old_purchase_amount_mean', 'new_hist_purchase_amount_skew', 'feature_2_y', 'old_purchase_date_diff', 'new_hist_hour_max', 'new_hist_category_3_min', 'new_month_max', 'old_installments_max', 'month', 'old_hour_min', 'hist_weekofyear_mean', 'new_month_min', 'hist_month_lag_median', 'new_hist_month_diff_median', 'hist_hour_nunique', 'new_month_lag_mean', 'new_weekday_max', 'hist_month_lag_max', 'new_hist_count', 'new_hist_weekend_mean', 'new_weekofyear_nunique', 'new_hist_dayofweek_min', 'new_hist_month_lag_max', 'new_hour_nunique', 'hist_authorized_flag_sum_x', 'old_authorized_flag__1_fraction', 'hist_card_id_count', 'quarter']
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt<load_from_csv>
df_train_old = pd.read_pickle(".. /input/features-from-old-model/train_old_features.pkl")
 df_test_old = pd.read_pickle(".. /input/features-from-old-model/test_old_features.pkl" )
def open_csv(file):
path = '/kaggle/input/competitive-data-science-predict-future-sales'
return pd.read_csv(os.path.join(path, file))
items = open_csv('items.csv')
 shops = open_csv('shops.csv')
 item_categories = open_csv('item_categories.csv')
 train = open_csv('sales_train.csv')
 submission = open_csv('sample_submission.csv')
 test = open_csv('test.csv')
<remove_duplicates>
df_train = pd.read_pickle(".. /input/elo-features-data-7-feb/train_df.pkl")
 df_test = pd.read_pickle(".. /input/elo-features-data-7-feb/test_df.pkl" )
attr = ['date', 'date_block_num', 'shop_id', 'item_id', 'item_cnt_day']
old_size = train.shape[0]
train.drop_duplicates(attr, inplace=True)
 print(f'Quantidade de elementos dupliciados: {old_size - train.shape[0]}' )<drop_column>
int_train = set(df_train_old.columns ).intersection(df_train.columns)- set(['card_id'])
 int_test = set(df_test_old.columns ).intersection(df_test.columns)- set(['card_id'] )
train.drop(columns=['date'], inplace=True)
 items.drop(columns=['item_name'], inplace=True)
 test.drop(columns=['ID'], inplace=True )<merge>
df_train.drop(columns = int_train, inplace = True)
 df_test.drop(columns = int_test, inplace = True )
train = pd.merge(train, items, on='item_id', how='left')
 test = pd.merge(test, items, on='item_id', how='left' )<drop_column>
df_train = pd.merge(df_train, df_train_old, on = 'card_id')
 df_test = pd.merge(df_test,df_test_old, on = 'card_id')
train = reduce_mem_usage(train )<drop_column>
del df_train_old, df_test_old
grid = reduce_mem_usage(grid )<groupby>
target = df_train['target']
del df_train['target']
sales_m = train.groupby(index_cols ).agg({'item_cnt_day': 'sum',
'item_price': np.mean} ).reset_index()
print(sales_m )<merge>
gc.collect()
sales_m = pd.merge(grid, sales_m, on=index_cols, how='left' ).fillna(0)
 print(f'Quantidade de elementos: {sales_m.shape[0]}
')
 print(sales_m )<merge>
df_oof = pd.DataFrame()
df_oof['card_id']= df_train['card_id']
df_oof['target'] = target
sales_m = pd.merge(sales_m, items, on='item_id', how='left' )<groupby>
param = {'num_leaves':62,
'min_data_in_leaf': 20,
'objective':'regression',
'max_depth': 8,
'learning_rate': 0.001,
"min_child_samples": 20,
"boosting": "gbdt",
"feature_fraction": 0.9,
"bagging_freq": 1,
"bagging_fraction": 0.9 ,
"bagging_seed": 11,
"metric": 'rmse',
"lambda_l1": 0.1,
"verbosity": -1,
"nthread": 4,
"random_state": 4590}
for i in range(1):
folds = StratifiedKFold(n_splits=10, shuffle=True, random_state=4590)
 oof = np.zeros(len(df_train))
predictions = np.zeros(len(df_test))
feature_importance_df = pd.DataFrame()
list_regressor = []
for fold_,(trn_idx, val_idx)in enumerate(folds.split(df_train,df_train['outliers'].values)) :
print("fold {}".format(fold_))
trn_data = lgb.Dataset(df_train.iloc[trn_idx][df_train_columns], label=target.iloc[trn_idx])
 val_data = lgb.Dataset(df_train.iloc[val_idx][df_train_columns], label=target.iloc[val_idx])
 num_round = 50000
clf = lgb.train(param, trn_data, num_round, valid_sets = [trn_data, val_data], verbose_eval=500, early_stopping_rounds = 500)
 oof[val_idx] = clf.predict(df_train.iloc[val_idx][df_train_columns], num_iteration=clf.best_iteration)
 fold_importance_df = pd.DataFrame()
fold_importance_df["Feature"] = df_train_columns
fold_importance_df["importance"] = clf.feature_importance()
fold_importance_df["fold"] = fold_ + 1
feature_importance_df = pd.concat([feature_importance_df, fold_importance_df], axis=0)
 predictions += clf.predict(df_test[df_train_columns], num_iteration=clf.best_iteration)/ folds.n_splits
list_regressor.append(clf)
 print(np.sqrt(mean_squared_error(oof, target)))
 df_oof['oof'] =oof
df_oof.to_csv("oof.csv" )
for type_id in ['item_id', 'shop_id', 'item_category_id']:
for column_id, aggregator, aggtype in [('item_price', np.mean, 'avg'), 
('item_cnt_day', np.sum, 'sum'), 
('item_cnt_day', np.mean, 'avg')]:
mean_df = train.groupby([type_id, 'date_block_num'] ).aggregate(aggregator ).reset_index() [[column_id, type_id, 'date_block_num']]
mean_df.columns = [type_id+'_'+aggtype+'_'+column_id, type_id, 'date_block_num']
sales_m = pd.merge(sales_m, mean_df, on=['date_block_num', type_id], how='left')
 print(sales_m.columns )<feature_engineering>
fip = best_features.sort_values(by="importance",ascending=False)
 plt.figure(figsize=(20,40))
imp = fip.groupby('Feature')['importance'].mean().sort_values(ascending=True)
 imp.to_csv("feature_importance.csv")
 imp.plot('barh')
 plt.show()
lag_variables = list(sales_m.columns[6:])+['item_cnt_day']
lags = [1, 2, 3, 4, 5, 6, 12]
def lag_features(df, sales_m):
for lag in lags:
sales_new_df = sales_m.copy()
sales_new_df.date_block_num += lag
sales_new_df = sales_new_df[index_cols+lag_variables]
sales_new_df.columns = index_cols + [f'{lag_feat}_lag_{lag}'
for lag_feat in lag_variables]
df = pd.merge(df, sales_new_df, on=index_cols, how='left')
 return df
lag_train = sales_m.copy()
lag_train = lag_features(lag_train, sales_m)
 print(f'Quantidade de atributos no dataframe: {lag_train.shape[1]}
')
 print(lag_train.columns )<data_type_conversions>
Se_imp = fip.groupby('Feature')['importance'].mean().sort_values(ascending=False)
 print(list(Se_imp.index))
<feature_engineering><EOS> 
for i in range(1):
sub_df = pd.DataFrame({"card_id":df_test["card_id"].values})
 sub_df["target"] = predictions
sub_df.to_csv("submission.csv", index=False )