<jupyter_start><jupyter_text>Pickle OneHotEncoder<jupyter_code># Create a Pickle OneHotEncoder file
import pickle

# Saving OneHotEncoder model to disk 
pickle.dump(ohe, open('OneHotEncoder.pkl','wb'))
# Test sample
echant_ohe_cat = [['France', 'Female']]
echo_numer =  [[596, 32, 3, 96709.07, 2, 0, 0, 41788.37]]

# Apply ohe on new_df (Echo)
cat_ohe_new = ohe.transform(echant_ohe_cat)

# Create a categorical column DataFrame (hot encoded)
echo_ohe_df_categ = pd.DataFrame(cat_ohe_new, columns = ohe.get_feature_names(input_features = categorical_cols))

# Create a Numeric Columns DataFrame
echo_df_numer = pd.DataFrame(echo_numer, columns=Numeric_cols[:-1])

# Concat with original data and remove original columns
echo_df_test = pd.concat([echo_df_numer, echo_ohe_df_categ], axis=1)
echo_df_test
# Test pkl OneHotEncoder 
import os
import pickle

# Apply OneHotEncoder 
if os.path.isfile("./OneHotEncoder.pkl"):
  OneHotEncoder = pickle.load(open("./OneHotEncoder.pkl", "rb"))
else:
  raise FileNotFoundError

#echo_df_test

transform = OneHotEncoder.transform(echant_ohe_cat)
transform
echo_final = np.concatenate((echo_numer, transform), axis=1)
echo_final<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10971524288107203, 'fraction_numerical': 0.021775544388609715, 'mean_word_length': 6.8618421052631575, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '441973', 'license': 'MIT', 'n_tokens_mistral': 463, 'n_tokens_neox': 439, 'n_words': 96, 'path': 'Create_pkl.ipynb', 'repo_name': 'kobi87/Prediction_of_customer_churn_at_a_bank', 'size': '1194'}