参考链接:https://mp.weixin.qq.com/s/kztRjHYJRJzG0h9pjfdwBw,公众号:Crossin的编程教室看到⼀个⼩技巧觉得很有⽤,记录学习⼀下。
如果通过模型⽣成了参数,但是系数⼩数位多且个数多,可以通过style.bar可视化的展⽰⼀下。
⼀、⽰例数据如下:
1 import numpy as np2 import pandas as pd3
4 coef = np.array([-0.01473407, -0.14209676, 0.0033682, 0.30169562, -0.89432301, -0.38844689, 0.0731774, .39652068])5
6 variables = np.array(['Age','SibSp','Fare','Parch','Pclass','Embarked_S','Embarked_C','Embarked_Q'])7
8 pd.DataFrame({'variable':variables,'coefficient':coef})
运⾏的结果如下:
variable coefficient0 Age -0.0147341 SibSp -0.1420972 Fare 0.0033683 Parch 0.3016964 Pclass -0.894323
5 Embarked_S -0.3884476 Embarked_C 0.0731777 Embarked_Q 0.396521
⼆、参数可视化:
1 data = pd.DataFrame({'variable':variables,'coefficient':coef})
2 data.round(decimals=2).sort_values('coefficient',ascending=False).style.bar(color=['grey','lightblue'],align='zero')
效果如下(保留两位⼩数→降序排列→可视化):
注:`align` must be one of {'left', 'zero',' mid'}——参数还需要仔细体会下
因篇幅问题不能全部显示,请点此查看更多更全内容