位置:- 正文

python中Box-Cox变换是什么(python cox)

编辑:rootadmin

推荐整理分享python中Box-Cox变换是什么(python cox),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:python中combobox,python cox,python boxcox,python boxcox,python boxcox变换,python中combobox,python box函数,python boxcox变换,内容如对您有帮助,希望把文章链接给更多的朋友!

概念

python中Box-Cox变换是什么(python cox)

1、Box-Cox变换是统计建模中常用的建模方法,主要用于连续响应变量不满足正态分布。

可采用Box-Cox变换。

2、使线性回归模型在满足线性、正态性、独立性和方差的同时不丢失信息。

在Box-Cox转换之前,有必要将数据归一化。

实例

#我们这里是对训练集和测试集一起归一化,也可以分开进行归一化,(分开)这种方式需要建立训练数据和测试数据分布一直的情况下,建议在数据量大的情况下使用。#绘图显示Box-Cox变换对数据分布影响cols_numeric_left=cols_numeric[0:13]cols_numeric_right=cols_numeric[13:]#这里是将特征分为两部分,前13个为第一部分##CheckeffectofBox-Coxtransformsondistributionsofcontinuousvariablestrain_data_process=pd.concat([train_data_process,train_data['target']],axis=1)fcols=6frows=len(cols_numeric_left)plt.figure(figsize=(4*fcols,4*frows))i=0forvarincols_numeric_left:dat=train_data_process[[var,'target']].dropna()i+=1plt.subplot(frows,fcols,i)sns.distplot(dat[var],fit=stats.norm);plt.title(var+'Original')plt.xlabel('')i+=1plt.subplot(frows,fcols,i)_=stats.probplot(dat[var],plot=plt)plt.title('skew='+'{:.4f}'.format(stats.skew(dat[var])))#计算数据集的偏度plt.xlabel('')plt.ylabel('')i+=1plt.subplot(frows,fcols,i)plt.plot(dat[var],dat['target'],'.',alpha=0.5)plt.title('corr='+'{:.2f}'.format(np.corrcoef(dat[var],dat['target'])[0][1]))i+=1plt.subplot(frows,fcols,i)trans_var,lambda_var=stats.boxcox(dat[var].dropna()+1)trans_var=scale_data(trans_var)sns.distplot(trans_var,fit=stats.norm);plt.title(var+'Tramsformed')plt.xlabel('')i+=1plt.subplot(frows,fcols,i)_=stats.probplot(trans_var,plot=plt)plt.title('skew='+'{:.4f}'.format(stats.skew(trans_var)))#归一化后,偏度明显变小,相关性变化不大plt.xlabel('')plt.ylabel('')i+=1plt.subplot(frows,fcols,i)plt.plot(trans_var,dat['target'],'.',alpha=0.5)plt.title('corr='+'{:.2f}'.format(np.corrcoef(trans_var,dat['target'])[0][1]))

以上就是python中Box-Cox变换的介绍,希望对大家有所帮助。更多Python学习指路:Python基础教程

本文链接地址:https://www.jiuchutong.com/zhishi/310525.html 转载请保留说明!
下一篇链接:https://www.jiuchutong.com/zhishi/310526.html
免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络