代码-Weka的NaiveBayes类
package kit.weka;
import java.io.File;
import weka.classifiers.CheckClassifier;
import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import weka.classifiers.evaluation.*;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.*;
public class NaiveBayesTest
{
public static void main(String[] args)
{
Instances ins = null;
Classifier cfs = null;
try
{
//读入训练测试样本
File file = new File("d:\\Program Files\\Weka-3-7\\data\\contact-lenses.arff");
ArffLoader loader = new ArffLoader();
loader.setFile(file);
ins = loader.getDataSet();
ins.setClassIndex(ins.numAttributes()-1);
//初始化分类器
cfs = (Classifier)Class.forName("weka.classifiers.bayes.NaiveBayes").newInstance();
//使用训练样本进行分类
cfs.buildClassifier(ins);
//使用测试样本测试分类器的学习效果
Instance testInst;
Evaluation testingEvaluation = new Evaluation(ins);
int length = ins.numInstances();
for(int i = 0; i < length ; i++)
{
testInst = ins.instance(i);
testingEvaluation.evaluateModelOnceAndRecordPrediction(cfs, testInst);
}
//打印分类结果
System.out.println("分类的正确率"+(1-testingEvaluation.errorRate()));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
代码-Weka的NaiveBayes类的更多相关文章
- 代码-Weka的决策树类J48
package kit.weka; /** * desc:试试Weka的决策树类 * <code>J48Test</code> * */ import java.io.Fi ...
- 代码-Weka的LinearRegression类
package kit.weka; import weka.classifiers.Evaluation; import weka.classifiers.functions.LinearRegres ...
- Myeclipse中把java代码导成UML类图
Myeclipse中把java代码导成UML类图 1.右键点击项目名称,选择New-------àUML2 Model 2.给类图命名 3.导成类图 1)如果要把整个项目导成类图,则把整个项目拖到类图 ...
- 从 Java 代码逆向工程生成 UML 类图和序列图
from:http://blog.itpub.net/14780914/viewspace-588975/ 本文面向于那些软件架构师,设计师和开发人员,他们想使用 IBM® Rational® Sof ...
- Android开源代码解读-基于SackOfViewAdapter类实现类似状态通知栏的布局
一般来说,ListView的列表项都会采用相同的布局,只是填充的内容不同而已,这种情况下,Android提供了convertView帮我们缓存列表项,达到循环利用的目的,开发者也会使用ViewHold ...
- final与 static的区别;static代码块以及嵌套类介绍
本篇文章主要分为两个模块进行介绍:1.final,staic,static final之间的异同:2. static 模块:3.嵌套类的概念 1.final,staic,static final之间的 ...
- 机器学习:weka中Evaluation类源码解析及输出AUC及交叉验证介绍
在机器学习分类结果的评估中,ROC曲线下的面积AOC是一个非常重要的指标.下面是调用weka类,输出AOC的源码: try { // 1.读入数据集 Instances data = new Inst ...
- 使用代码向一个普通的类注入Spring的实例
转载请在页首注明作者与原文地址 一:应用场景 什么是普通的类,就是没有@Controller,@Service,@Repository,@Component等注解修饰的类,同时xml文件中,也没有相应 ...
- C#代码示例_定义类
默认情况下,类声明为内部的,即只有当前项目中的代码才能访问它.可以使用internal访问修饰符关键字显示指定. 除了两个访问修饰符关键字(public, internal)外,还可以指定类是抽象的( ...
随机推荐
- configure: error: zlib library and headers are required
configure: error: zlib library and headers are required (1)直接看是zlib没安装导致的,yum list |grep zlib* 看到的是全 ...
- 【BZOJ】1925: [Sdoi2010]地精部落 DP+滚动数组
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1925 题意:输入一个数N(1 <= N <= 4200),问将这些数排列成折线 ...
- entity framework in mysql
To start using Entity Framework 6 and Visual Studio 2013 is necessary to install MySQL for Visual St ...
- python 统计单词个数
根据一篇英文文章统计其中单词出现最多的10个单词. # -*- coding: utf-8 -*-import urllib2import refrom collections import Coun ...
- Oracle数据库的下载和安装
那天分享一下Oracle的下载和安装的过程,有需要的朋友可以借鉴参考一下.如有雷同不胜感激! 首先可以到Oracle的官网下载Oracle的最次年版本的Oracle数据库.一下是个人下载的数据库版本百 ...
- Linux下OpenSSL 安装图文详解
安装环境: 操作系统:CentOs6.3 OpenSSL Version:openssl-1.0.0e.tar.gz 目前版本最新的SSL地址为http://www.openssl.or ...
- IndexReader和IndexWriter的生命周期
http://youyang-java.iteye.com/blog/1731205 对于IndexReader而言,反复使用 IndexReader .open打开会有很大的开销,所以一般在整个程序 ...
- hdu 4878 ZCC loves words AC自动机+中国剩余定理+快速幂
题意就不说了. 分析:折腾好几天自己写的代码还是看了别人代码后发现几乎没什么复杂度的差别,可是就是一直超时,后来干脆照着别人写啊,一直WA,就在准备放弃干脆先写这篇博客的时候,又看了一眼WA的代码,发 ...
- leetcode面试准备:Kth Largest Element in an Array
leetcode面试准备:Kth Largest Element in an Array 1 题目 Find the kth largest element in an unsorted array. ...
- 安装gem invalid date format in specification错误的解决方法
别的不说,报错信息直接贴图: 解决方法: 1.找到你环境目录下的spec,例如:D:\Ruby187\lib\ruby\gems\1.8\specifications. 2.找到引起错误文件的gems ...