<jupyter_start><jupyter_text>PreparationThe purpose of this notebook is really to show you a few good practices in model pipelining, and Python in general:- Saving Models- Pickling- Referencing Python variables using `eval()`We'll also use the models saved here in the next notebook.<jupyter_code>all_seasons_df = pd.read_csv('/Users/johnmetzger/Desktop/Coding/Projects/Project3/all_seasons_df')

X_train, X_test, y_train, y_test = model_selection.train_test_split(all_seasons_df.drop('WL', axis=1), 
                                                                    all_seasons_df.WL, 
                                                                    random_state=123)
# Define models.
lr_model = linear_model.LogisticRegression()
nb_model = naive_bayes.GaussianNB()
knn_model = neighbors.KNeighborsClassifier()
svc_model = svm.SVC(probability=True, gamma="scale")
rf_model = ensemble.RandomForestClassifier(n_estimators=100)
et_model = ensemble.ExtraTreesClassifier(n_estimators=100)
ada_model = ensemble.AdaBoostClassifier()

# Notice that these model names (strings) match the models themselves (variables, above)
models = ["lr_model", "nb_model", "knn_model", "svc_model", "rf_model", "et_model", "ada_model"]
import os

if not os.path.exists('models'):
    os.makedirs('models')
# This step took 5m24s on Friday February 5th, 2021

for model_name in models:
    curr_model = eval(model_name)  # The string refers us to the variable
    
    curr_model.fit(X_train, y_train)
    
    # Notice the syntax here.
    with open(f"models/{model_name}.pickle", "wb") as pfile:
        pickle.dump(curr_model, pfile)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09642207398423287, 'fraction_numerical': 0.011522134627046696, 'mean_word_length': 3.6610169491525424, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '286194', 'license': 'MIT', 'n_tokens_mistral': 535, 'n_tokens_neox': 505, 'n_words': 126, 'path': '.ipynb_checkpoints/NBA_Emsemble_Prep_nb4-checkpoint.ipynb', 'repo_name': 'JGarrechtMetzger/Project3', 'size': '1649'}