visualize_5_31.py 1.2 KB

1234567891011121314151617181920212223
  1. def reg_resid_plot(df="dataframe", yhat=None, resid=None, stdresid=None, dim=(6, 4), colordot='#4a4e4d',
  2. colorline='#2ab7ca', r=300, ar=0, dotsize=6, valphaline=1, valphadot=1, linewidth=1,
  3. markerdot="o", show=False, figtype='png', theme=None):
  4. if theme == 'dark':
  5. general.dark_bg()
  6. fig, ax = plt.subplots(figsize=dim)
  7. if resid is not None:
  8. plt.scatter(df[yhat], df[resid], color=colordot, s=dotsize, alpha=valphadot, marker=markerdot)
  9. plt.axhline(y=0, color=colorline, linestyle='--', linewidth=linewidth, alpha=valphaline)
  10. plt.xlabel("Fitted")
  11. plt.ylabel("Residuals")
  12. general.get_figure(show, r, figtype, 'resid_plot', theme)
  13. else:
  14. print ("Error: Provide residual data")
  15. if stdresid is not None:
  16. plt.scatter(df[yhat], df[stdresid], color=colordot, s=dotsize, alpha=valphadot, marker=markerdot)
  17. plt.axhline(y=0, color=colorline, linestyle='--', linewidth=linewidth, alpha=valphaline)
  18. plt.xlabel("Fitted")
  19. plt.ylabel("Standardized Residuals")
  20. general.get_figure(show, r, figtype, 'std_resid_plot', theme)
  21. else:
  22. print ("Error: Provide standardized residual data")