您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用WEKA API定义输入数据以进行聚类

使用WEKA API定义输入数据以进行聚类

我相信您必须创建自己的实例。下面,我展示了如何从具有两个属性(纬度和经度)的数组创建新实例。

import weka.core.Attribute;
import weka.core.DenseInstance;
import weka.core.FastVector;
import weka.core.Instances;

public class AttTest {

    public static void main(String[] args) throws Exception
    {
        double[] one={0,1,2,3};
        double[] two={3,2,1,0};
        double[][] both=new double[2][4];
        both[0]=one;
        both[1]=two;

        Instances to_use=AttTest.buildArff(both);
        System.out.println(to_use.toString());
    }

  public static Instances buildArff(double[][] array) throws Exception
  {
         FastVector      atts = new FastVector();
         atts.addElement(new Attribute("lat")); //latitude
         atts.addElement(new Attribute("lon")); //longitude

         // 2. create Instances object
         Instances test = new Instances("location", atts, 0);

         // 3. fill with data
         for(int s1=0; s1 < array[0].length; s1=s1+1)
         {
             double vals[] = new double[test.numAttributes()];
             vals[0] = array[0][s1];
             vals[1] = array[1][s1];
             test.add(new DenseInstance(1.0, vals));
         }

         return(test);
  }
}
其他 2022/1/1 18:32:28 有478人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶