【问题标题】:Rapid miner: CSV with real numbers with commas instead of dots快速矿工:带有逗号而不是点的实数的 CSV
【发布时间】:2011-08-18 20:27:01
【问题描述】:

我在使用 RapidMiner 导入 CSV 文件时遇到问题。 浮点值用逗号代替整数和十进制值之间的分隔点写入。

有人知道如何正确导入以这种方式格式化的值吗?

样本数据:

BMI;1;0;1;1;1;blue;-0,138812155;0,520378909;5;0;50;107;0;9;0;other;good;2011 BMI;1;0;1;1;1;pink;-0,624654696;;8;0;73;120;1;3;0,882638889;other;good;2011

Rapid miner 实际上将其解释为“多项式”。将其强制为“真实”只会导致对“0”值的正确解释。

谢谢

【问题讨论】:

  • 您能否向我们展示几行 CSV,以便我们测试我们可能提出的解决方案,而以后不会发现它们是错误的?

标签: csv floating-point machine-learning data-mining rapidminer


【解决方案1】:

这似乎是一个非常古老的要求。不确定这是否会对您有所帮助,但这可能会对其他有类似情况的人有所帮助。

第 1 步:在“读取 CSV”操作符的“导入配置向导”下,确保选择“分号”作为分隔符

第 2 步:使用“猜测类型”运算符。属性过滤器类型 -> 子集,选择属性 -> 选择属性 8、9 和 16(基于上面的示例),将“小数点字符”更改为“,”,您应该已经设置好了。

希望这对(某人!)有所帮助

【讨论】:

    【解决方案2】:

    使用分号作为分隔符。您可以使用java.util.Scanner 读取每一行。 String.split() 以分号分隔。当您获得带有逗号的标记时,您可以使用String.replace() 将逗号更改为小数。然后你可以使用Float.parseFloat()

    希望这能回答你的问题。

    【讨论】:

    • 感谢您的回答。不幸的是,我刚刚开始学习 RapidMiner,只使用 GUI。没有任何简单的方法可以使用 GUI 来完成吗?
    • 对不起。我不熟悉 RapidMiner。祝你好运。
    【解决方案3】:
    public static void main(String args){
        BufferedReader br = new BufferedReader(new FileReader("c:\\path\\semicolons and numbers and commas.csv"));
        try {
            for(String line; (line=br.readLine()) != null);) {
                //Variable line now has a single line from the file. This code will execute for each line.
                String array = line.split(";");// Split on the semicolon. Beware of changing this. This uses regex which means that some characters mean something like . means anything, not just dots.
                double firstDouble = Double.parseDouble(array[7].replace(',','.')); // Get field 7 (the eighth field) and turn it into a double (high precision floating point). Replace , with . so it will not make an error
                System.err.println("Have a number " + firstDouble);
                System.err.println("Can play with it " + (firstDouble * 2.0));
            }
        }finally{
            br.close(); // Free resources (and unlock file on Windows).
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 1970-01-01
      相关资源
      最近更新 更多