剔除无用变量
数据中常有一些质量比较差或对建模没有意义的变量,可以定义一些规则,对其进行直接删除,以减少计算量,比如
(1)缺失率过高的变量
(2)单值变量
(3)分类数过多的变量
A | |
1 | =file("D://house_prices_train.csv").import@qtc() |
2 | =A1.fname() |
3 | =A2.((y=~,A1.align@a([true,false],!eval(y)))) |
4 | =A2.new(~:col,A3(#)(1).len():null_no,round(null_no/A1.len(),3):null_rate,A1.field(#).icount():icount,if(!sum(A1.field(#)),"string","num"):type) |
5 | =A4.select(null_rate<0.9 && icount>1 && !(type=="string" && icount>100)).(col).concat(",") |
6 | =A1.new(${A5}) |
A2 获取字段名
A3 将每个字段按照是否缺失分成两组
A4 统计每个字段的缺失数,缺失率,distinct值的数量,数据类型
A5 剔除缺失率大于0.9的变量、单值变量和分类数大于100的变量
A6 变量筛选后的表格