Java和Weka如何提供测试集并预测属性

时间:2019-05-12 19:17:02

标签: java weka

我有一个训练集,我使用SimpleKMeans算法构建了两个集群,我需要知道如何向模型提供测试集并获得答案。

我发现了多种解决方案,但仅适用于分类器(ZeroR,OneR等),而没有用于测试集群的方法(SimpleKmeans,FatherFirst ...)

         private Instances data;
         private SimpleKMeans kMeans = new SimpleKMeans();


        data.setClassIndex(data.numAttributes() - 1);
        Remove filter = new Remove();
        filter.setAttributeIndices("" + (data.classIndex() + 1));
        filter.setInputFormat(data);
        Instances dataClusterer = Filter.useFilter(data, filter);
        kMeans.buildClusterer(dataClusterer);

        ClusterEvaluation eval = new ClusterEvaluation();
        eval.setClusterer(kMeans);
        eval.evaluateClusterer(data);


        return eval.clusterResultsToString();


The above code is use for "Classes to cluster evaluation", in my case I use my last class to create two clusters (YES or NO) :
   Final cluster centroids:
                               Cluster#
Attribute           Full Data         0         1
                      (614.0)   (472.0)   (142.0)
=================================================
Gender                   Male      Male      Male
Married                   Yes       Yes       Yes
Dependents                  0         0         1
Education            Graduate  Graduate  Graduate
Self_Employed              No        No        No
ApplicantIncome     5403.4593 5289.7331 5781.4789
CoapplicantIncome   1621.2458 1591.6655  1719.569
LoanAmount           146.4122  146.0406  147.6471
Loan_Amount_Term          342  347.4534  323.8732
Credit_History         0.8422    0.8983    0.6557
Property_Area       Semiurban Semiurban     Urban


Cluster 0 <-- Y
Cluster 1 <-- N

0 个答案:

没有答案