<jupyter_start><jupyter_text>Lgbm<jupyter_code>df_train_dataset = pd.read_pickle('data/df/df_train_dataset_with_ft.pkl')
df_validation_dataset = pd.read_pickle('data/df/df_validation_dataset_with_ft.pkl')
continuous_features = joblib.load('data/iterables/continuous_features_with_ft.joblib')
categorical_features = joblib.load('data/iterables/categorical_features_with_ft.joblib')
target_features = joblib.load('data/iterables/target_features.joblib')
target_transformer = joblib.load('models/preprocessing/target_transformer_with_ft.joblib')
df_train_dataset.shape, df_validation_dataset.shape
X = df_train_dataset[categorical_features + continuous_features].values
y = df_train_dataset[target_features].values.flatten()
print(X.shape, y.shape)
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.85, test_size=0.15, shuffle=True, random_state=10)
print(X_train.shape, X_test.shape, y_train.shape, y_test.shape)
NUM_REGRESSORS = 3
regressors = []

i = 0
seeds = [  6,  66, 219,  91, 236, 201, 242,   4, 145,  37,  80]
seeds = [  6,  63, 219]
rkf = KFold(n_splits=NUM_REGRESSORS, shuffle=True, random_state=21)
for train_index, test_index in tqdm_notebook(rkf.split(X_train, y_train)):
    XTr, XTe = X_train[train_index], X_train[test_index]
    ytr, yte = y_train[train_index], y_train[test_index]
    print(XTr.shape, XTe.shape, ytr.shape, yte.shape)
    
    feature_names = categorical_features + continuous_features
    reg_lgbm, y_pred, score = run_lgbm(XTr, XTe, ytr, yte, feature_names, categorical_features, seed=seeds[i])
    regressors.append(reg_lgbm)
    i += 1
predictions_dataset = {'y_pred_{}'.format(i): None for i in range(regressors.__len__())}
for i, regressor in enumerate(tqdm_notebook(regressors)):
    predictions_dataset['y_pred_{}'.format(i)] = regressor.predict(X_test, regressor.best_iteration)
df_preditions = pd.DataFrame(predictions_dataset)
df_preditions.head()
def fo_minimize(z, *args):
    df = args[0]
    y_test = args[1]
    
    s_ = pd.Series(np.zeros(df.shape[0], ))
    for midx, multiplier in enumerate(z):
        s_ += df.iloc[:, midx] * multiplier

    s_ = s_ / np.sum(z)
    return mean_squared_error(y_test, s_.values) ** .5
xopt, fopt , _, _, _ = spo.fmin(fo_minimize, [0.5] * NUM_REGRESSORS, args=(df_preditions, y_test), maxiter=600, disp=False, full_output=True)
xopt, fopt 
X_val = df_validation_dataset[categorical_features + continuous_features].values
predictions_val_dataset = {'y_pred_val{}'.format(i): None for i in range(regressors.__len__())}
for i, regressor in enumerate(tqdm_notebook(regressors)):
    predictions_val_dataset['y_pred_val{}'.format(i)] = regressor.predict(X_val, regressor.best_iteration)
df_preditions_val = pd.DataFrame(predictions_val_dataset)
s_ = pd.Series(np.zeros(df_preditions_val.shape[0], ))
for midx, multiplier in enumerate(xopt):
    s_ += df_preditions_val.iloc[:, midx] * multiplier
s_ = s_ / np.sum(xopt)
y_pred_val = target_transformer.inverse_transform(np.expand_dims(s_.values, axis=1))
df_validation_dataset[target_features] = y_pred_val
df_validation_dataset[['reservation_id', 'amount_spent_per_room_night_scaled']].to_csv('submission.csv', index=False)
fig, ax = plt.subplots(nrows=1, ncols=1)
fig.set_size_inches(24, 24)
lgb.plot_importance(regressors[0], ax=ax, height=0.5, max_num_features=100);
fig, ax = plt.subplots(nrows=1, ncols=1)
fig.set_size_inches(24, 24)
lgb.plot_importance(regressors[1], ax=ax, height=0.5, max_num_features=100);
fig, ax = plt.subplots(nrows=1, ncols=1)
fig.set_size_inches(24, 24)
lgb.plot_importance(regressors[2], ax=ax, height=0.5, max_num_features=100);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1336443468715697, 'fraction_numerical': 0.024972557628979142, 'mean_word_length': 6.855603448275862, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '107291', 'license': 'MIT', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1418, 'n_words': 221, 'path': 'decommissioned/02_Algorithms_0.3.2.ipynb', 'repo_name': 'mdalvi/club-mahindra-data-olympics', 'size': '3644'}