stefan-jansen / machine-learning-for-trading

Code for Machine Learning for Algorithmic Trading, 2nd edition.
https://ml4trading.io
12.57k stars 4.03k forks source link

07_linear_models/05_predicting_stock_returns_with_linear_regression.ipynb--->Syntax error for top_coeffs of Ridge Regression #286

Closed Fdu-lijiachen closed 1 year ago

Fdu-lijiachen commented 1 year ago

best_alpha = ridge_scores.groupby('alpha').ic.mean().idxmax() fig, axes = plt.subplots(ncols=2, figsize=(15, 5)) plot_ic_distribution(ridge_scores[ridge_scores.alpha == best_alpha], ax=axes[0]) axes[0].set_title('Daily Information Coefficients') top_coeffs = ridge_coeffs.loc[best_alpha].abs().sort_values().head(10).index #I think there may be some error top_coeffs.tolist() ridge_coeffs.loc[best_alpha, top_coeffs].sort_values().plot.barh(ax=axes[1], title='Top 10 Coefficients') sns.despine() fig.tight_layout()

###################################################### -> "top_coeffs = ridge_coeffs.loc[best_alpha].abs().sort_values().head(10).index" maybe use sort_values(ascending = False) is better here?Since we want to caculate the most relevant coefficients,which means have top 10 high values?

stefan-jansen commented 1 year ago

Fair point.