Weka 仅将数字更改为名义 [英] Weka only changing numeric to nominal

查看:32
本文介绍了Weka 仅将数字更改为名义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要导入 Weka 的 CSV 文件.所有变量都以数字形式导入.我需要将其中 3 个更改为名义值.但是,当我在其上放置 numerictonominal 过滤器时 - 所有变量都会发生变化.我只想改变3.

1) 有没有办法通过过滤器改变一些2)或者你可以在导入过程中设置它.如果是这样,我也想不通.

解决方案

我假设您使用的是 Weka Explorer (GUI).要将过滤器应用于特定属性,请执行以下操作.

第 1 步:在预处理选项卡中选择您的过滤器
第 2 步:单击选择"按钮右侧的框(打开一个新窗口)
第 3 步:在 attributeIndices 框中输入您的自定义范围

如果您在过滤器窗口中选择更多"按钮,您将获得不同选项的说明以及您可以提供的值.

在您的特定情况下,过滤器默认应用于第一个到最后一个属性.您应该更改范围以反映您的个人需求.

====编辑====
如果您使用的是 Java API,以下代码将为您指明正确的方向.

<预><代码>导入 weka.core.Instances;导入 weka.filters.Filter;导入 weka.filters.unsupervised.attribute.NumericToNominal;公共课主要{public static void main(String[] args) 抛出异常{//加载训练实例Instances originalTrain=//...加载具有数字属性的数据NumericToNominal convert= new NumericToNominal();字符串[]选项=新字符串[2];选项[0]="-R";选项[1]="1-2";//变量范围以生成数字convert.setOptions(options);convert.setInputFormat(originalTrain);实例 newData=Filter.useFilter(originalTrain, convert);System.out.println("之前");for(int i=0; i<2; i=i+1){System.out.println("Nominal?"+originalTrain.attribute(i).isNominal());}System.out.println("之后");for(int i=0; i<2; i=i+1){System.out.println("名义?"+newData.attribute(i).isNominal());}}}

I have a CSV file that I am importing into Weka. All variables are importing as numeric. I need to change 3 of them to nominal. However when I place numerictonominal filter on it- all variables change. I only want to change 3.

1) Is there a way to just change a few via the filter 2) Or can you set it during the import. If so, I can't figure that out either.

解决方案

I assume you are using the Weka Explorer (GUI). To apply the filter to specific attributes do the following.

Step 1: Select your filter in the preprocess tab
Step 2: Click on the box to the right of the "Choose" button (a new window opens)
Step 3: In the attributeIndices box enter your custom ranges

If you select the "More" button in the filter window you will get an explanation of the different options and the values you can supply.

In your particular case, the filter is by default applied to the first through last attributes. You should change the range to reflect your personal needs.

====Edit====
If you are using the Java API, the following code will point you in the right direction.

 
import weka.core.Instances;
import weka.filters.Filter;
import weka.filters.unsupervised.attribute.NumericToNominal;

public class Main {

    public static void main(String[] args) throws Exception
    {

        //load training instances
        Instances originalTrain= //...load data with numeric attributes 

        NumericToNominal convert= new NumericToNominal();
        String[] options= new String[2];
        options[0]="-R";
        options[1]="1-2";  //range of variables to make numeric

        convert.setOptions(options);
        convert.setInputFormat(originalTrain);

        Instances newData=Filter.useFilter(originalTrain, convert);

        System.out.println("Before");
        for(int i=0; i<2; i=i+1)
        {
            System.out.println("Nominal? "+originalTrain.attribute(i).isNominal());
        }

        System.out.println("After");
        for(int i=0; i<2; i=i+1)
        {
            System.out.println("Nominal? "+newData.attribute(i).isNominal());
        }

    }

} 

这篇关于Weka 仅将数字更改为名义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆