<jupyter_start><jupyter_text>Build a LASSO model.<jupyter_code>## 1. Read the data serialized by visualize.ipynb
data = pd.read_pickle('./data/rates.p')

## 2. Add up to 3 lags and drop holes created from lagging, or holidays.
lagged = add_lags(data, 3).dropna()

## 3. Train/test split.
lagged.index = pd.to_datetime(lagged.index, utc=True)
X_train, y_train, X_holdout, y_holdout = split_sample_bytime(lagged)

## 4. Train model.
model = LassoLarsIC(criterion = 'bic',
                    normalize = True,
                    positive = False).fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Compare the training error and the out-of-time holdout error.<jupyter_code>pd.DataFrame({'Training Set': model.score(X_train, y_train),
              'Holdout Set': model.score(X_holdout, y_holdout)},
             index = ['R^2']
            ).round(3)<jupyter_output><empty_output><jupyter_text>Performance check: predicted rates vs the heldout actual rates (2018 time period).<jupyter_code>pd.DataFrame({'Predicted': model.predict(X_holdout),
              'Actual': y_holdout}
            ).plot(title='Out-of-Sample Performance')<jupyter_output><empty_output><jupyter_text>Print the coefficients of the LASSO model.<jupyter_code>pd.DataFrame(model.coef_, 
             index = X_train.columns,
             columns = ['Coefficient']
            ).applymap(lambda x: str(round(x)) if x == 0 else x)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1262135922330097, 'fraction_numerical': 0.009015256588072122, 'mean_word_length': 3.7467105263157894, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '213805', 'license': 'MIT', 'n_tokens_mistral': 508, 'n_tokens_neox': 484, 'n_words': 104, 'path': 'run_model.ipynb', 'repo_name': 'zjohn77/lasso_example', 'size': '1442'}