<jupyter_start><jupyter_text>Using Numeric Features Only<jupyter_code>X_trn_encoded.shape
X_trn, Y_trn = loader.load("trn_set", ignore_categorical=True, nrows=100000)
X_dev, Y_dev = loader.load("dev_set", ignore_categorical=True, nrows=10000)
gbm = GradientBoostingClassifier(random_state=0)
gbm.fit(X_trn, Y_trn)
plt.figure(figsize=(12, 8))
feat_imp = pd.Series(gbm.feature_importances_, X_trn.columns).sort_values(ascending=False)
feat_imp.plot(kind='bar', title='Feature Importances')
plt.ylabel('Feature Importance Score')
plt.savefig("figs/features_ranking.png")
Y_pred = gbm.predict(X_dev)
plt.figure(figsize=(15, 7))

ax1 = plt.subplot(1, 2, 1)

value_counts = Counter(Y_dev)
_ = ax1.pie(x = list(value_counts.values()), 
            labels = list(value_counts.keys()),
            autopct='%1.1f%%', 
            labeldistance = 1.1)
ax1.set_title('Development Set Label')

ax2 = plt.subplot(1, 2, 2)

value_counts = Counter(Y_pred)
_ = ax2.pie(x = list(value_counts.values()), 
            labels = list(value_counts.keys()),
            autopct='%1.1f%%',
            labeldistance = 1.1)

ax2.set_title('Predicted Label')

plt.show()
print("Accuracy : %.4g" % metrics.accuracy_score(Y_dev.values, Y_pred))<jupyter_output>Accuracy : 0.3607<jupyter_text>Add categorical features<jupyter_code>X_trn, Y_trn = loader.load("trn_set", ignore_categorical=False, nrows=100000)
X_dev, Y_dev = loader.load("dev_set", ignore_categorical=False, nrows=10000)
ohe = preprocessing.OneHotEncoder(handle_unknown="ignore")
ohe.fit(X_trn[loader.cat_cols].fillna(0))
X_trn_encoded = loader.encode(ohe, X_trn)
X_dev_encoded = loader.encode(ohe, X_dev)
gbm = GradientBoostingClassifier(random_state=0)
gbm.fit(X_trn_encoded, Y_trn)
Y_pred = gbm.predict(X_dev_encoded)
Y_dev.value_counts() / len(Y_dev)
print("Accuracy : %.4g" % metrics.accuracy_score(Y_dev.values, Y_pred))
X_trn.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14713610089332632, 'fraction_numerical': 0.03047819232790331, 'mean_word_length': 6.104477611940299, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '231577', 'license': 'MIT', 'n_tokens_mistral': 811, 'n_tokens_neox': 763, 'n_words': 104, 'path': 'case_study/shutterfly/gbm_basic.ipynb', 'repo_name': 'shawlu95/Data_Science_Toolbox', 'size': '1903'}