数据分析-记录

1、特征重要性提取:
对于xgb,lgb等模型,都会有model.feature_importance_方法,对特征的影响程度展示。

2、函数参数(*arg,**kwargs)
*args 用来将参数打包成tuple给函数体调用
**kwargs 打包关键字参数成dict给函数体调用
例子:
在这里插入图片描述
3、删除多余变量的方法
通过删除一整行index实现:

data = {
    "a":[1,2,3],
    "b":[4,5,6],
    "c":[7,8,9]   
}
df = pd.DataFrame(data,columns=['a','b','c'],index=['x','y','z'])
print(df)
df.drop(df[df['b']==5].index)

在这里插入图片描述
4、from scipy.special import boxcoxlp
box-cox变换的用处:

  1. 通常对于y进行log变换,因为诸如线性模型、SVM等要求target variable是服从正态分布的
  2. 线性回归模型满足线性性、独立性、方差齐性以及正态性的同时,又不丢失信息,此种变换称之为Box—Cox变换。

Box-Cox变换的正态变换:
在这里插入图片描述
没有Box-Cox变换的回归:
在这里插入图片描述
Box-Cox变换之后的回归:
在这里插入图片描述
变换方法:

skewness = skewness[abs(skewness) > 0.75]

from scipy.special import boxcox1p
skewed_features = skewness.index
lam = 0.15
for feat in skewed_features:
    #all_data[feat] += 1
    all_data[feat] = boxcox1p(all_data[feat], lam)
 
发布了24 篇原创文章 · 获赞 3 · 访问量 1570

猜你喜欢

转载自blog.csdn.net/xfxlesson/article/details/101380826