Skip to Content
Hands-On Machine Learning for Algorithmic Trading
book

Hands-On Machine Learning for Algorithmic Trading

by Stefan Jansen
December 2018
Beginner to intermediate
684 pages
21h 9m
English
Packt Publishing
Content preview from Hands-On Machine Learning for Algorithmic Trading

Lasso regression using sklearn

The lasso implementation looks very similar to the ridge model we just ran. The main difference is that lasso needs to arrive at a solution using iterative coordinate descent whereas ridge can rely on a closed-form solution:

nfolds = 250alphas = np.logspace(-8, -2, 13)scaler = StandardScaler()lasso_results, lasso_coeffs = pd.DataFrame(), pd.DataFrame()for i, alpha in enumerate(alphas):    coeffs, test_results = [], []    lr_lasso = Lasso(alpha=alpha)    for i, (train_dates, test_dates) in enumerate(time_series_split(dates, nfolds=nfolds)):        X_train = model_data.loc[idx[train_dates], features]        y_train = model_data.loc[idx[train_dates], target]        lr_lasso.fit(X=scaler.fit_transform(X_train), y=y_train) X_test = model_data.loc[idx[test_dates] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Machine Learning for Algorithmic Trading - Second Edition

Machine Learning for Algorithmic Trading - Second Edition

Stefan Jansen

Publisher Resources

ISBN: 9781789346411Supplemental Content