import numpy as np from plotnine import * import statsmodels.api as sm import pandas as pd #残差分析图 df = pd.read_csv('Residual_Analysis_Data.csv') results = sm.OLS(df.y2,df.x).fit() df['predicted']=results.predict() df['residuals']=df.predicted-df.y2 df['Abs_Residuals']=np.abs(df.residuals) base_Residuals=(ggplot(df,aes(x='x', y='y2'))+ geom_point(aes(fill='Abs_Residuals',size='Abs_Residuals'),shape='o',color='black')+ geom_line(aes(y='predicted'),color='lightgrey')+ geom_point(aes(y='predicted'),shape='o')+ geom_segment(aes(xend='x',yend='predicted'),alpha=.2)+ scale_fill_gradientn(colors=["black","red"])+ guides(fill=guide_legend(title='Rresidual'), size = guide_legend(title='Rresidual'))+ theme( axis_title=element_text(size=18,face='plain',color='black'), axis_text=element_text(size=16,face='plain',color='black'), aspect_ratio=1.1, figure_size=(5,5), dpi=100 ) ) print(base_Residuals)
python残差分析图
最新推荐文章于 2022-06-29 16:40:53 发布