0

这是我的 CSV 数据提取和转换代码:

Schema schema = new Schema.Builder()
            .addColumnsString("RowNumber")
            .addColumnInteger("CustomerId")
            .addColumnString("Surname")
            .addColumnInteger("CreditScore")
            .addColumnCategorical("Geography",Arrays.asList("France","Spain","Germany"))
            .addColumnCategorical("Gender",Arrays.asList("Male","Female"))
            .addColumnsInteger("Age","Tenure","Balance","NumOfProducts","HasCrCard","IsActiveMember","EstimatedSalary","Exited").build();
    TransformProcess transformProcess = new TransformProcess.Builder(schema)
                                            .removeColumns("RowNumber","Surname","CustomerId")
                                            .categoricalToInteger("Gender")
                                            .categoricalToOneHot("Geography").build();
    RecordReader reader = new CSVRecordReader(1,',');
    reader.initialize(new FileSplit(new ClassPathResource("Churn_Modelling.csv").getFile()));
    TransformProcessRecordReader transformProcessRecordReader = new TransformProcessRecordReader(reader,transformProcess);
    System.out.println("args = " + transformProcessRecordReader.next() + "");

我刚刚尝试打印第一条记录:

args = [619, 1, 0, 0, 1, 42, 2, 0, 1, 1, 1, 101348.88, 1]

比如后面跟 619 的三个值 -> 1, 0, 0 我想保留 619 后面跟 0, 0。

基本上我想将第一个类别保留为基本类别,并从基本类别中预测其他类别以避免任何多重共线关系(虚拟变量陷阱)

我怎么做?有人可以就此提出建议吗?

4

1 回答 1

1

您可以使用 检查最终转换模式transformProcess.finalSchema,并使用删除相应的第二列

TransformProcess transformProcess = ... same as before...
        .categoricalToOneHot("Geography")
        .removeColumns("Geography[France]")
        .build()
于 2018-05-16T20:50:08.163 回答