weka使用教程

weka使用教程
Weka是一个强大的开源机器学习软件,它提供了各种功能和算法来进行数据挖掘和预测分析。

以下是一个简单的Wea使
用教程,帮助您了解如何使用它来进行数据分析和建模。

1. 安装Weka:首先,您需要下载并安装Weka软件。

您可以从官方网站上下载Weka的最新版本,并按照安装说明进行安装。

2. 打开Weka:安装完成后,打开Weka软件。

您将看到一个欢迎界面,上面列出了各种不同的选项和功能。

选择“Explorer”选项卡,这将帮助您导航和执行不同的任务。

3. 导入数据:在Explorer选项卡上,点击“Open file”按钮以导入您的数据集。

选择您要导入的数据文件,并确认数据文件的格式和结构。

4. 数据预处理:在导入数据之后,您可能需要对数据进行预处理,以清除噪声和处理缺失值。

在Weka中,您可以使用各种过滤器和转换器来处理数据。

点击“Preprocess”选项卡,然后
选择适当的过滤器和转换器来定义您的预处理流程。

5. 数据探索:在数据预处理之后,您可以使用Weka的可视化工具来探索您的数据。

点击“Classify”选项卡,然后选择“Visualize”选项。

这将显示您的数据集的可视化图表和统计信息。

6. 建立模型:一旦您对数据进行了足够的探索,您可以使用Weka的各种机器学习算法建立模型。

在“Classify”选项卡上选
择“Choose”按钮,并从下拉菜单中选择一个适当的分类算法。

然后,使用“Start”按钮训练模型并评估模型的性能。

7. 模型评估:一旦您建立了模型,您可以使用Weka提供的评
估指标来评估模型的性能。

在“Classify”选项卡上,选择“Evaluate”选项,Weka将自动计算模型的准确性、精确度、召回率等指标。

8. 导出模型:最后,一旦您满意您的模型性能,您可以将模型导出到其他应用程序或格式中。

在Weka中,点击“Classify”选项卡,选择“Save model”选项,并指定模型的保存位置和格式。

这是一个简单的Wea使用教程,帮助您了解如何使用Weka
进行数据挖掘和预测分析。

根据您的具体需求和数据集,您可以深入研究Weka的各种功能和算法,以更好地利用它进行数
据建模和分析。

合集下载

Weka_数据挖掘软件使用指南

Weka_数据挖掘软件使用指南

Weka 数据挖掘软件使用指南1.Weka简介该软件是WEKA的全名是怀卡托智能分析环境(Waikato Environment for Knowledge Analysis),它的源代码可通过/ml/weka得到。

Weka作为一个公开的数据挖掘工作平台,集合了大量能承担数据挖掘任务的机器学习算法,包括对数据进行预处理,分类,回归、聚类、关联规则以及在新的交互式界面上的可视化。

如果想自己实现数据挖掘算法的话,可以看一看Weka的接口文档。

在Weka中集成自己的算法甚至借鉴它的方法自己实现可视化工具并不是件很困难的事情。

2.Weka启动打开Weka主界面后会出现一个对话框,如图:主要使用右方的四个模块,说明如下:❑Explorer:使用Weka探索数据的环境,包括获取关联项,分类预测,聚簇等;❑Experimenter:运行算法试验、管理算法方案之间的统计检验的环境;❑KnowledgeFlow:这个环境本质上和Explorer所支持的功能是一样的,但是它有一个可以拖放的界面。

它有一个优势,就是支持增量学习;❑SimpleCLI:提供了一个简单的命令行界面,从而可以在没有自带命令行的操作系统中直接执行Weka命令(某些情况下使用命令行功能更好一些)。

3.主要操作说明点击进入Explorer模块开始数据探索环境。

3.1主界面进入Explorer模式后的主界面如下:3.1.1标签栏主界面最左上角(标题栏下方)的是标签栏,分为五个部分,功能依次是:❑Preprocess(数据预处理):选择和修改要处理的数据;❑Classify(分类):训练和测试关于分类或回归的学习方案;❑Cluster(聚类):从数据中学习聚类;❑Associate(关联):从数据中学习关联规则;❑Select attributes(属性选择):选择数据中最相关的属性;❑Visualize(可视化):查看数据的交互式二维图像。

3.1.2载入、编辑数据标签栏下方是载入数据栏,功能如下:❑Open file:打开一个对话框,允许你浏览本地文件系统上的数据文件(.dat);❑Open URL:请求一个存有数据的URL 地址;❑Open DB:从数据库中读取数据;❑Generate:从一些数据生成器中生成人造数据。

weka使用-徐延昆

weka使用-徐延昆

Weka使用小报告实验目的:熟悉weka界面;熟悉weka explore 相关模块功能及操作;测试自带数据进行本次实验实验内容:通过weka自带测试数据熟悉weka基本操作实验过程:1、打卡weka界面Weka启动界面2、打开explorer3、打开自带数据打开一个名为contact-lenses的arff数据文件,可以从基本界面发现这个数据里的一些特征:(1)数据关系名称:contact-lenses(2)数据实例个数:24(3)数据每个实例属性个数:5(4)总权重:243、观察基本数据信息红色标注的部分就是数据属性,可以看到这组数据共有五个属性:(1)Age(2)Spectacle-prescrip(3)Astigmatism(4)Tear-prod-rate(5)Contact-lenses这个标注的是所选属性的一些信息:属性名称:age属性取值个数:3丢失率:0单值个数:0属性类型:分类型表中是属性具体取值,比如说age:(1)年轻(2)接近老年(3)老年右下角的直方图就是具体属性中包含其他属性的图,比如说上图所选就是age属性,每个age里包括contact比例就是蓝、红、浅蓝的比例。

这些可以更换,只要class属性中选择其他的类。

上面这个直方图就可以完全显示各种类之间比例的关系。

4、使用过滤器5、使用分类器选择分类器为one-B 6选择完分类器选项之后可以选择测试方式,我使用了3种测试方法,对5个属性都进行了测试6、聚类操作7、关联分析8、可视化分析9、收获和问题:(1)熟悉了基本操作(2)对一些术语还不是很理解,分类聚类等(3)在进行一次聚类操作的时候出现了不能停止的情况(4)测试的数据个数太少,没有尝试使用一个大数据,导致最后可视化看不出什么关系。

电算化常用数据挖掘与机器学习工具操作指南

电算化常用数据挖掘与机器学习工具操作指南

电算化常用数据挖掘与机器学习工具操作指南在当今数字化时代,数据的快速增长和复杂性使得传统的数据处理方式已无法满足实际需求。

因此,数据挖掘和机器学习成为了解决大规模数据处理的重要工具。

本文将介绍电算化常用的数据挖掘和机器学习工具的操作指南,帮助读者更好地理解和应用这些工具。

一、WEKA软件WEKA是一个十分常用的机器学习工具,其功能强大、易于使用。

以下是WEKA软件的操作指南:1. 安装WEKA软件下载WEKA安装文件并按照提示完成软件的安装。

2. 数据预处理在WEKA中,选择“预处理”选项,对数据进行清洗、去除噪声、处理缺失值等操作,以获得干净的数据集。

3. 特征选择通过选择合适的特征,提高模型的准确性和效率。

使用WEKA的“特征选择”功能,可以根据不同的特征选择算法来进行特征选择。

4. 模型构建与评估选择合适的机器学习算法,使用WEKA中的“分类”或“回归”功能,进行模型的构建与训练。

同时,可以使用WEKA提供的交叉验证、混淆矩阵等评估工具,评估模型的性能。

5. 模型应用与保存完成模型的构建和评估后,可以使用WEKA对新数据进行预测和分类。

同时,也可以将模型保存下来,以备将来使用。

二、Python编程语言与相关库Python是一种广泛应用于数据挖掘和机器学习领域的编程语言,其丰富的库使得数据处理和模型构建变得更为便捷。

以下是使用Python进行数据挖掘和机器学习的操作指南:1. 安装Python环境与相关库首先,安装Python编程环境,并通过pip命令安装相关库,如NumPy、Pandas、Scikit-learn等。

2. 数据加载与预处理使用Pandas库加载数据,并利用库中的函数进行数据清洗、去除异常值等预处理操作。

3. 特征工程在数据挖掘和机器学习中,特征工程是提取和选择合适的特征,以增加模型的准确性和泛化能力。

可以利用特征选择、特征提取、特征变换等方法进行特征工程。

利用Scikit-learn库中的各种机器学习算法,可以构建多种模型。

weka数据预处理标准化方法说明

weka数据预处理标准化方法说明

weka数据预处理标准化方法说明Weka(Waikato Environment for Knowledge Analysis)是一套用于数据挖掘和机器学习的开源软件工具集,提供了丰富的功能,包括数据预处理、分类、回归、聚类等。

在Weka中,数据预处理是一个关键的步骤,其中标准化是一个常用的技术,有助于提高机器学习算法的性能。

下面是在Weka中进行数据标准化的一般步骤和方法说明:1. 打开Weka:启动Weka图形用户界面(GUI)或使用命令行界面。

2. 加载数据:选择“Explorer”选项卡,然后点击“Open file”按钮加载您的数据集。

3. 选择过滤器(Filter):在“Preprocess”选项卡中,选择“Filter”子选项卡,然后点击“Choose”按钮选择一个过滤器。

4. 选择标准化过滤器:在弹出的对话框中,找到并选择标准化过滤器。

常见的标准化过滤器包括:- Normalize:这个过滤器将数据标准化为给定的范围,通常是0到1。

- Standardize:使用这个过滤器可以将数据标准化为零均值和单位方差。

- AttributeRange:允许您手动指定每个属性的范围,以进行标准化。

5. 设置标准化选项:选择标准化过滤器后,您可能需要配置一些选项,例如范围、均值和方差等,具体取决于选择的过滤器。

6. 应用过滤器:配置完成后,点击“Apply”按钮,将标准化过滤器应用于数据。

7. 保存处理后的数据:如果需要,您可以将标准化后的数据保存到文件中。

8. 查看结果:在数据预处理完成后,您可以切换到“Classify”选项卡,选择一个分类器,并使用标准化后的数据进行模型训练和测试。

记住,具体的步骤和选项可能会因Weka版本的不同而有所差异,因此建议查阅Weka文档或在线资源以获取更具体的信息。

此外,标准化的适用性取决于您的数据和机器学习任务,因此在应用标准化之前,最好先了解您的数据的分布和特征。

weka配置教程

weka配置教程

一、WEKA的安装在WEKA的安装文件中有weka-3-6-9.exe和weka-3-6-9jre.exe,这两个软件我们安装一个即可,这里主要介绍weka-3-6-9.exe的安装步骤1.安装Java运行环境下载jdk-7u21-windows-i586.exe(最新版)安装包,双击安装包进行安装,根据安装向导提示,点击下一步即可,安装完成以后可以通过命令提示符输入java–version 进行验证,若出现如下图所示,表示安装成功。

2.配置环境变量右击我的电脑,点击属性,出现如下界面:、选择高级——>环境变量,如图所示:出现环境变量配置界面:双击Path,然后出现编辑系统变量窗口:在变量值编辑框中,将光标移动至最后,添加一个分号“;”,然后将java的jdk安装路径追加到编辑框最后,我的系统中安装路径为:C:\ProgramFiles\Java\jdk1.7.0_21\bin,所以在编辑框最后写入:“; C:\ProgramFiles\Java\jdk1.7.0_21\bin”,即可完成环境变量的配置。

3.weka-3-6-9.exe双击此文件开始进行安装,在出现的窗口中点击Next,然后点击I Agree,再点击Next,此时出现如下窗口,Browse左边的区域是WEKA的默认安装路径,我们可以点击Browse选择我们想要安装WEKA的位置,然后点击窗口下方的NEXT,也可以不点击Browse直接将WEKA安装到默认的目录下,即直接点击窗口下方的NEXT,在新出现的窗口中点击Install开始安装,等待几秒种后点击Next,在新窗口中会有一个Start Weka单选框(默认情况下是选中的),如果我们想安装完成后就启动WEKA,那么我们就直接点击新窗口下方的FINISH 完成安装,如果我们不想立即启动WEKA可以单击Start Weka前面的单选框,然后点击FINISH即可完成安装,此时WEKA已经安装到我们的电脑中。

WEKA操作入门

WEKA操作入门

WEKA操作入门WEKA的全名是怀卡托智能分析环境(Waikato Environment for Knowledge Analysis),它的源代码可通过/ml/weka得到。

同时weka也是新西兰的一种鸟名,而WEKA的主要开发者来自新西兰。

WEKA作为一个公开的数据挖掘工作平台,用于非商业目的的研究行为,集合了大量能承担数据挖掘任务的机器学习算法,包括对数据进行预处理,分类,回归、聚类、关联规则以及在新的交互式界面上的可视化。

WEKA的接口是开放的,可以查看weka的接口文档,在weka中集成自己的算法甚至借鉴它的方法自己实现可视化工具。

2005年8月,在第11届ACM SIGKDD国际会议上,怀卡托大学的Weka小组荣获了数据挖掘和知识探索领域的最高服务奖,Weka系统得到了广泛的认可,被誉为数据挖掘和机器学习历史上的里程碑,是现今最完备的数据挖掘工具之一(已有11年的发展历史)。

Weka 的每月下载次数已超过万次。

1.数据格式跟很多电子表格或数据分析软件一样,WEKA所处理的数据集是图1那样的一个二维的表格。

图1. weather.arff数据集WEKA中的术语。

表格里的一个横行称作一个实例(Instance),相当于统计学中的一个样本,或者数据库中的一条记录。

竖行称作一个属性(Attrbute),相当于统计学中的一个变量,或者数据库中的一个字段。

这样一个表格,或者叫数据集,在WEKA看来,呈现了属性之间的一种关系(Relation)。

图1中一共有14个实例,5个属性,关系名称为“weather”。

WEKA存储数据的格式是ARFF(Attribute-Relation File Format)文件,这是一种ASCII文本文件。

图1所示的二维表格存储在如下的ARFF文件中。

这也就是WEKA自带的“weather.arff”文件,在WEKA安装目录的“data”子目录下可以找到。

relation weather@attribute outlook {sunny, overcast, rainy}@attribute temperature real@attribute humidity real@attribute windy {TRUE, FALSE}@attribute play {yes, no}@datasunny,85,85,FALSE,nosunny,80,90,TRUE,noovercast,83,86,FALSE,yesrainy,70,96,FALSE,yesrainy,68,80,FALSE,yesrainy,65,70,TRUE,noovercast,64,65,TRUE,yessunny,72,95,FALSE,nosunny,69,70,FALSE,yesrainy,75,80,FALSE,yessunny,75,70,TRUE,yesovercast,72,90,TRUE,yesovercast,81,75,FALSE,yesrainy,71,91,TRUE,no以“%”开始的行是注释,WEKA将忽略这些行。

weka操作介绍讲解学习

6. 区域7是区域5中选中属性的直 方图。若数据集的某个属性是目
标变量,直方图中的每个长方形
就会按照该变量的比例分成不同
颜色的段。默认地,分类或回归
任务的默认目标变量是数据集的
最后一个属性。要想换个分段的
依据,即目标变量,在区域7上 方的下拉框中选个不同的分类属
性就可以了。下拉框里选上
“No Class”或者一个数值属性会 变成黑白的直方图。
wekቤተ መጻሕፍቲ ባይዱ操作介绍
在KnowledgeFlow 窗口顶部有八个标签: DataSources--数据载入器 DataSinks--数据保存器 Filters--筛选器 Classifiers--分类器 Clusterers--聚类器 Associations—关联器 Evaluation—评估器 Visualization—可视化
关联运行结果
此课件下载可自行编辑修改,仅供参考! 感谢您的支持,我们努力做得更好!谢谢
3 4
5 8
1 2
6 7
1.区域1的几个选项卡是用来切换不同的 挖掘任务面板。
Preprocess(数据预处理) Classify(分类) Cluster(聚类) Associate(关联分析) Select Attributes(选择属性) Visualize(可视化)
2. 区域2是一些常用按钮。包括打开数据, 保存及编辑功能。我们可以在这里把 “bank-data.csv”,另存为“bank-data.arff”
Cluster
主要算法包括: SimpleKMeans — 支持分类属性的K均值算法 DBScan — 支持分类属性的基于密度的算法 EM — 基于混合模型的聚类算法 FathestFirst — K中 心点算法 OPTICS — 基于密度的另一个算法 Cobweb — 概念聚类算法 sIB — 基于信息论的聚类算法,不支持分类属性 XMeans — 能自动确定簇个数的扩展K均值算法,不 支持分类属性

WEKA中文详细教程

导出数据
Weka可以将分析结果导出为多种格式,如CSV、ARFF、LaTeX等,用户可以通过“文件”菜单 选择“导出数据”来导出数据。
数据清理
缺失值处理
Weka提供了多种方法来处理缺失值, 如删除含有缺失值的实例、填充缺失 值等。
异常值检测
Weka提供了多种异常值检测方法, 如基于距离的异常值检测、基于密度 的异常值检测等。
Weka中文详细教程
目录
• Weka简介 • 数据预处理 • 分类算法 • 关联规则挖掘 • 回归分析 • 聚类分析 • 特征选择与降维 • 模型评估与优化
01
Weka简介
Weka是什么
01 Weka是一款开源的数据挖掘软件,全称是 "Waikato Environment for Knowledge Analysis",由新西兰怀卡托大学开发。
解释性强等优点。
使用Weka进行决策树 分类时,需要设置合 适的参数,如剪枝策 略、停止条件等,以 获得最佳分类效果。
决策树分类结果易于 理解和解释,能够为 决策提供有力支持。
贝叶斯分类器
贝叶斯分类器是一种 基于概率的分类算法, 通过计算不同类别的 概率来进行分类。
Weka中的朴素贝叶斯 分类器是一种基于贝 叶斯定理的简单分类 器,适用于特征之间 相互独立的场景。
08
模型评估与优化
交叉验证
01
交叉验证是一种评估机器学习模型性能的常用方法,通过将数据集分成多个子 集,然后使用其中的一部分子集训练模型,其余子集用于测试模型。
02
常见的交叉验证方法包括k-折交叉验证和留出交叉验证。在k-折交叉验证中, 数据集被分成k个大小相近的子集,每次使用其中的k-1个子集训练模型,剩余 一个子集用于测试。

Weka入门教程

Weka入门教程3. 分类与回归背景知识WEKA把分类(Classification)和回归(Regression)都放在“Classify”选项卡中,这是有原因的。

在这两个任务中,都有一个目标属性(输出变量)。

我们希望根据一个样本(WEKA 中称作实例)的一组特征(输入变量),对目标进行预测。

为了实现这一目的,我们需要有一个训练数据集,这个数据集中每个实例的输入和输出都是已知的。

观察训练集中的实例,可以建立起预测的模型。

有了这个模型,我们就可以新的输出未知的实例进行预测了。

衡量模型的好坏就在于预测的准确程度。

在WEKA中,待预测的目标(输出)被称作Class属性,这应该是来自分类任务的“类”。

一般的,若Class属性是分类型时我们的任务才叫分类,Class属性是数值型时我们的任务叫回归。

选择算法这一节中,我们使用C4.5决策树算法对bank-data建立起分类模型。

我们来看原来的“bank-data.csv”文件。

“ID”属性肯定是不需要的。

由于C4.5算法可以处理数值型的属性,我们不用像前面用关联规则那样把每个变量都离散化成分类型。

尽管如此,我们还是把“Children”属性转换成分类型的两个值“YES”和“NO”。

另外,我们的训练集仅取原来数据集实例的一半;而从另外一半中抽出若干条作为待预测的实例,它们的“pep”属性都设为缺失值。

经过了这些处理的训练集数据在这里下载;待预测集数据在这里下载。

我们用“Explorer”打开训练集“bank.arff”,观察一下它是不是按照前面的要求处理好了。

切换到“Classify”选项卡,点击“Choose”按钮后可以看到很多分类或者回归的算法分门别类的列在一个树型框里。

3.5版的WEKA中,树型框下方有一个“Filter...”按钮,点击可以根据数据集的特性过滤掉不合适的算法。

我们数据集的输入属性中有“Binary”型(即只有两个类的分类型)和数值型的属性,而Class变量是“Binary”的;于是我们勾选“Binary attributes”“Numeric attributes”和“Binary class”。

Weka简单使用说明

PrimerPROTECTED guest · Join · Help · Sign In ·PAGE DISCUSSION (2)HISTORY NOTIFY ME Join this WikiRecent Changes Manage WikiSearch Home All pages All tags All files FAQ Not So FAQTroubleshooting Introduction WEKA is a comprehensive toolbench for machine learning and data mining. Its main strengths lie in theclassification area, where all current ML approaches --and quite a few older ones --have been implementedwithin a clean, object-oriented Java class hierarchy. Regression, Association Rules and clustering algorithmshave also been implemented.However, WEKA is also quite complex to handle --amply demonstrated by many questions on the WEKAmailing list . Concerning the graphical user interface, the WEKA development group offers documentation forthe Explorer and the Experimenter. However, there is little documentation on using the command line interfaceto WEKA, although it is essential for realistic learning tasks.This document serves as a practical introduction to the command line interface. Since there has been a recentreorganization in class hierarchies for WEKA, all examples may only work with versions 3.4.4 and above only(until the next reorganization, that is ;-) Basic concepts and issues can more easily be transferred to earlierversions, but the specific examples may need to be slightly adapted (mostly removing the third class hierarchylevel and renaming some classes).While for initial experiments the included graphical user interface is quite sufficient, for in-depth usage thecommand line interface is recommended, because it offers some functionality which is not available via the GUI-and uses far less memory. Should you get Out of Memory errors, increase the maximum heap size for yourjava engine, usually via -Xmx1024M or -Xmx1024m for 1GB. Windows users should modify RunWeka.bat toadd the parameter -Xmx1024M before the -jar option, yielding java -Xmx1024M -jar weka.jar -thedefault setting of 16 to 64MB is usually too small. If you get errors that classes are not found, check yourCLASSPATH : does it include weka.jar ? You can explicitly set CLASSPATH via the -cp command line optionas well.We will begin by describing basic concepts and ideas. Then, we will describe the weka.filters package, which isused to transform input data, e.g. for preprocessing, transformation, feature generation and so on.Then we will focus on the machine learning algorithms themselves. These are called Classifiers in WEKA. Wewill restrict ourselves to common settings for all classifiers and shortly note representatives for all mainapproaches in machine learning.Afterwards, practical examples are given. In Appendix A you find an example java program which utilizesvarious WEKA classes in order to give some functionality which is not yet integrated in WEKA --namely tooutput predictions for test instances within a cross-validation. It also outputs the complete class probabilitydistribution.Finally, in the doc directory of WEKA you find a documentation of all java classes within WEKA. Prepare touse it since this overview is not intended to be complete. If you want to know exactly what is going on, take alook at the mostly well-documented source code, which can be found in weka-src.jar and can be extracted viathe jar utility from the Java Development Kit.If you find any bugs, less comprehensible statements, have comments or want to offer suggestions, pleasecontact me .Basic conceptsDatasetA set of data items, the dataset, is a very basic concept of machine learning. A dataset is roughly equivalent to a two-dimensional spreadsheet or database table. In WEKA, it is implemented by the Instances class. A dataset is a collection of examples, each one of class Instance . Each Instance consists of a number ofattributes, any of which can be nominal (= one of a predefined list of values), numeric (= a real or integernumber) or a string (= an arbitrary long list of characters, enclosed in "double quotes"). The externalrepresentation of an Instances class is an ARFF file, which consists of a header describing the attribute typesand the data as comma-separated list. Here is a short, commented example. A complete description of theARFF file format can be found here .% This is a toy example, the UCI weather dataset.% Any relation to real weather is purely coincidental.}}Comment lines at the beginning of the dataset should give an indication of its source, context and meaning.@relation golfWeatherMichigan_1988/02/10_14daysHere we state the internal name of the dataset. Try to be as comprehensive as possible.@attribute outlook {sunny, overcast rainy}@attribute windy {TRUE, FALSEHere we define two nominal attributes, outlook and windy. The former has three values: sunny, overcast and rainy; the latter two: TRUE and FALSE. Nominal values with special characters, commas or spaces are enclosed in 'single quotes'.@attribute temperature real@attribute humidity realThese lines define two numeric attributes. Instead of real, integer or numeric can also be used. While double floating point values are stored internally, only seven decimal digits are usually processed.@attribute play {yes, no}The last attribute is the default target or class variable used for prediction. In our case it is a nominal attribute with two values, making this a binary classification problem.@datasunny,FALSE,85,85,nosunny,TRUE,80,90,noovercast,FALSE,83,86,yesrainy,FALSE,70,96,yesrainy,FALSE,68,80,yesThe rest of the dataset consists of the token @data, followed by comma-separated values for the attributes --one line per example. In our case there are five examples.In our example, we have not mentioned the attribute type string, which defines "double quoted" string attributes for text mining. In recent WEKA versions, date/time attribute types are also supported.By default, the last attribute is considered the class/target variable, i.e. the attribute which should be predicted as a function of all other attributes. If this is not the case, specify the target variable via -c. The attribute numbers are one-based indices, i.e. -c 1specifies the first attribute.Some basic statistics and validation of given ARFF files can be obtained via the main() routine ofweka.core.Instances:java weka.core.Instances data/soybean.arffweka.core offers some other useful routines, e.g. converters.C45Loader and converters.CSVLoader, which can be used to import C45 datasets and comma/tab-separated datasets respectively, e.g.:java weka.core.converters.CSVLoader data.csv >data.arffjava weka.core.converters.C45Loader c45_filestem >data.arffClassifierAny learning algorithm in WEKA is derived from the abstract Classifier class. Surprisingly little is needed for a basic classifier: a routine which generates a classifier model from a training dataset (= buildClassifier) and another routine which evaluates the generated model on an unseen test dataset (= classifyInstance), or generates a probability distribution for all classes (= distributionForInstance).A classifier model is an arbitrary complex mapping from all-but-one dataset attributes to the class attribute. The specific form and creation of this mapping, or model, differs from classifier to classifier. For example, ZeroR's model just consists of a single value: the most common class, or the median of all numeric values in case of predicting a numeric value (= regression learning). ZeroR is a trivial classifier, but it gives a lower bound on the performance of a given dataset which should be significantly improved by more complex classifiers. As such it is a reasonable test on how well the class can be predicted without considering the other attributes.Later, we will explain how to interpret the output from classifiers in detail --for now just focus on the Correctly Classified Instances in the section Stratified cross-validation and notice how it improves from ZeroR to J48: java weka.classifiers.rules.ZeroR -t weather.arffjava weka.classifiers.trees.J48 -t weather.arffThere are various approaches to determine the performance of classifiers. The performance can most simply be measured by counting the proportion of correctly predicted examples in an unseen test dataset. This value is the accuracy, which is also 1-ErrorRate. Both terms are used in literature.The simplest case is using a training set and a test set which are mutually independent. This is referred to as hold-out estimate. To estimate variance in these performance estimates, hold-out estimates may be computed by repeatedly resampling the same dataset --i.e. randomly reordering it and then splitting it into training and test sets with a specific proportion of the examples, collecting all estimates on test data and computing average and standard deviation of accuracy.A more elaborate method is cross-validation. Here, a number of folds n is specified. The dataset is randomly reordered and then split into n folds of equal size. In each iteration, one fold is used for testing and the other n-1folds are used for training the classifier. The test results are collected and averaged over all folds. This gives the cross-validation estimate of the accuracy. The folds can be purely random or slightly modified to create the same class distributions in each fold as in the complete dataset. In the latter case the cross-validation is called stratified. Leave-one-out (loo) cross-validation signifies that n is equal to the number of examples. Out of necessity, loo cv has to be non-stratified, i.e. the class distributions in the test set are not related to those in the training data. Therefore loo cv tends to give less reliable results. However it is still quite useful in dealing with small datasets since it utilizes the greatest amount of training data from the dataset.weka.filtersThe weka.filters package is concerned with classes that transforms datasets --by removing or adding attributes, resampling the dataset, removing examples and so on. This package offers useful support for data preprocessing, which is an important step in machine learning.All filters offer the options -i for specifying the input dataset, and -o for specifying the output dataset. If any of these parameters is not given, this specifies standard input resp. output for use within pipes. Other parameters are specific to each filter and can be found out via -h, as with any other class. The weka.filters package is organized into supervised and unsupervised filtering, both of which are again subdivided into instance and attribute filtering. We will discuss each of the four subsection separately.weka.filters.supervisedClasses below weka.filters.supervised in the class hierarchy are for supervised filtering, i.e. taking advantage of the class information. A class must be assigned via -c, for WEKA default behaviour use -c last.attributeDiscretize is used to discretize numeric attributes into nominal ones, based on the class information, via Fayyad & Irani's MDL method, or optionally with Kononeko's MDL method. At least some learning schemes or classifiers can only process nominal data, e.g. rules.Prism; in some cases discretization may also reduce learning time.java weka.filters.supervised.attribute.Discretize -i data/iris.arff -o iris-nom.java weka.filters.supervised.attribute.Discretize -i data/cpu.arff -o cpu-classvNominalToBinary encodes all nominal attributes into binary (two-valued) attributes, which can be used to transform the dataset into a purely numeric representation, e.g. for visualization via multi-dimensional scaling.java weka.filters.supervised.attribute.NominalToBinary -i data/contact-lenses.arKeep in mind that most classifiers in WEKA utilize transformation filters internally, e.g. Logistic and SMO, so you will usually not have to use these filters explicity. However, if you plan to run a lot of experiments, pre-applying the filters yourself may improve runtime performance.instanceResample creates a stratified subsample of the given dataset. This means that overall class distributions are approximately retained within the sample. A bias towards uniform class distribution can be specified via -B.java weka.filters.supervised.instance.Resample -i data/soybean.arff -o soybean-5 java weka.filters.supervised.instance.Resample -i data/soybean.arff -o soybean-uStratifiedRemoveFolds creates stratified cross-validation folds of the given dataset. This means that per default the class distributions are approximately retained within each fold. The following example splits soybean.arff into stratified training and test datasets, the latter consisting of 25% (=1/4) of the data.java weka.filters.supervised.instance.StratifiedRemoveFolds -i data/soybean.arff -c last-N4-F1-Vjava weka.filters.supervised.instance.StratifiedRemoveFolds -i data/soybean.arff -c last-N4-F1weka.filters.unsupervisedClasses below weka.filters.unsupervised in the class hierarchy are for unsupervised filtering, e.g. the non-stratified version of Resample. A class should not be assigned here.attributeStringToWordVector transforms string attributes into a word vectors, i.e. creating one attribute for each word which either encodes presence or word count (-C) within the string. -W can be used to set an approximate limit on the number of words. When a class is assigned, the limit applies to each class separately. This filter is useful for text mining.Obfuscate renames the dataset name, all attribute names and nominal attribute values. This is intended for exchanging sensitive datasets without giving away restricted information.Remove is intended for explicit deletion of attributes from a dataset, e.g. for removing attributes of the iris dataset:java weka.filters.unsupervised.attribute.Remove -R1-2-i data/iris.arff -o iris java weka.filters.unsupervised.attribute.Remove -V-R3-last -i data/iris.arff -instanceResample creates a non-stratified subsample of the given dataset, i.e. random sampling without regard to the class information. Otherwise it is equivalent to its supervised variant.java weka.filters.unsupervised.instance.Resample -i data/soybean.arff -o soybeanRemoveFolds creates cross-validation folds of the given dataset. The class distributions are not retained. The following example splits soybean.arff into training and test datasets, the latter consisting of 25% (=1/4) of the data.java weka.filters.unsupervised.instance.RemoveFolds -i data/soybean.arff -o soyb java weka.filters.unsupervised.instance.RemoveFolds -i data/soybean.arff -o soybRemoveWithValues filters instances according to the value of an attribute.java weka.filters.unsupervised.instance.RemoveWithValues -i data/soybean.arff \ -o soybean-without_herbicide_injury.arff -V-C last-L19weka.classifiersClassifiers are at the core of WEKA. There are a lot of common options for classifiers, most of which are related to evaluation purposes. We will focus on the most important ones. All others including classifier-specificparameters can be found via -h, as usual.-t specifies the training file (ARFF format)-T specifies the test file in (ARFF format). If this parameter is missing, a crossvalidation will be performed (default: 10-fold cv)-x This parameter determines the number of folds for the cross-validation. A cv will only be performed if -T is missing.-c As we already know from the weka.filters section, this parameter sets the class variable with a one-based index.-d The model after training can be saved via this parameter. Each classifier has a different binary format for the model, so it can only be read back by the exact same classifier on a compatible dataset. Only the model on the training set is saved, not the multiple models generated via cross-validation.-l Loads a previously saved model, usually for testing on new, previously unseen data. In that case, a compatible test file should be specified, i.e. the same attributes in the same order.-p #If a test file is specified, this parameter shows you the predictions and one attribute (0 for none) for all test instances. If no test file is specified, this outputs nothing. In that case, you will have to use callClassifier from Appendix A.-i A more detailed performance description via precision, recall, true-and false positive rate is additionally output with this parameter. All these values can also be computed from the confusion matrix.-o This parameter switches the human-readable output of the model description off. In case of support vector machines or NaiveBayes, this makes some sense unless you want to parse and visualize a lot ofinformation.We now give a short list of selected classifiers in WEKA. Other classifiers below weka.classifiers in package overview may also be used. This is more easy to see in the Explorer GUI.•trees.J48 A clone of the C4.5 decision tree learner•bayes.NaiveBayes A Naive Bayesian learner. -K switches on kernel density estimation for numerical attributes which often improves performance.•meta.ClassificationViaRegression-W functions.LinearRegression Multi-response linear regression.•functions.Logistic Logistic Regression.•functions.SMO Support Vector Machine (linear, polynomial and RBF kernel) with Sequential Minimal Optimization Algorithm due to [Platt, 1998]. Defaults to SVM with linear kernel, -E 5 -C 10gives an SVM with polynomial kernel of degree 5 and lambda=10.•lazy.KStar Instance-Based learner. -E sets the blend entropy automatically, which is usuallypreferable.•lazy.IBk Instance-Based learner with fixed neighborhood. -K sets the number of neighbors to use.IB1is equivalent to IBk -K 1•rules.JRip A clone of the RIPPER rule learner.Based on a simple example, we will now explain the output of a typical classifier, weka.classifiers.trees.J48. Consider the following call from the command line, or start the WEKA explorer and train J48 on weather.arff:java weka.classifiers.trees.J48 -t data/weather.arff -iJ48 pruned tree------------------outlook = sunny| humidity <= 75: yes (2.0)| humidity > 75: no (3.0)outlook = overcast: yes (4.0)outlook = rainy| windy = TRUE: no (2.0)| windy = FALSE: yes (3.0)Number of Leaves : 5Size of the tree : 8The first part, unless you specify -o, is a human-readable form of the training set model. In this case, it is a decision tree. outlook is at the root of the tree and determines the first decision. In case it is overcast, we'll always play golf. The numbers in (parentheses) at the end of each leaf tell us the number of examples in this leaf. If one or more leaves were not pure (= all of the same class), the number of misclassified examples wouldalso be given, after a /slash/Time taken to build model: 0.05 secondsTime taken to test model on training data: 0 secondsAs you can see, a decision tree learns quite fast and is evaluated even faster. E.g. for a lazy learner, testing would take far longer than training.= Error on training data ==Correctly Classified Instance 14 100 %Incorrectly Classified Instances 0 0 %Kappa statistic 1Mean absolute error 0Root mean squared error 0Relative absolute error 0 %Root relative squared error 0 %Total Number of Instances 14== Detailed Accuracy By Class ==TP Rate FP Rate Precision Recall F-Measure Class1 0 1 1 1 yes1 0 1 1 1 no== Confusion Matrix ==a b <--classified as9 0 | a = yes0 5 | b = noThis is quite boring: our classifier is perfect, at least on the training data --all instances were classified correctly and all errors are zero. As is usually the case, the training set accuracy is too optimistic. The detailed accuracy by class, which is output via -i, and the confusion matrix is similarily trivial.== Stratified cross-validation ==Correctly Classified Instances 9 64.2857 %Incorrectly Classified Instances 5 35.7143 %Kappa statistic 0.186Mean absolute error 0.2857Root mean squared error 0.4818Relative absolute error 60 %Root relative squared error 97.6586 %Total Number of Instances 14== Detailed Accuracy By Class ==TP Rate FP Rate Precision Recall F-Measure Class0.778 0.6 0.7 0.778 0.737 yes0.4 0.222 0.5 0.4 0.444 no== Confusion Matrix ==a b <--classified as7 2 | a = yes3 2 | b = noThe stratified cv paints a more realistic picture. The accuracy is around 64%. The kappa statistic measures the agreement of prediction with the true class --1.0 signifies complete agreement. The following error values are not very meaningful for classification tasks, however for regression tasks e.g. the root of the mean squared error per example would be a reasonable criterion. We will discuss the relation between confusion matrix and other measures in the text.The confusion matrix is more commonly named contingency table. In our case we have two classes, andtherefore a 2x2 confusion matrix, the matrix could be arbitrarily large. The number of correctly classified instances is the sum of diagonals in the matrix; all others are incorrectly classified (class "a" gets misclassified as "b" exactly twice, and class "b" gets misclassified as "a" three times).The True Positive (TP)rate is the proportion of examples which were classified as class x, among all examples which truly have class x, i.e. how much part of the class was captured. It is equivalent to Recall. In the confusion matrix, this is the diagonal element divided by the sum over the relevant row, i.e. 7/(7+2)=0.778 for class yes and 2/(3+2)=0.4 for class no in our example.The False Positive (FP)rate is the proportion of examples which were classified as class x, but belong to a different class, among all examples which are not of class x. In the matrix, this is the column sum of class x minus the diagonal element, divided by the rows sums of all other classes; i.e. 3/5=0.6 for class yes and2/9=0.222 for class no.The Precision is the proportion of the examples which truly have class x among all those which were classified as class x. In the matrix, this is the diagonal element divided by the sum over the relevant column, i.e. 7/(7+3) =0.7 for class yes and 2/(2+2)=0.5 for class no.The F-Measure is simply 2*Precision*Recall/(Precision+Recall), a combined measure for precision and recall.These measures are useful for comparing classifiers. However, if more detailed information about the classifier's predictions are necessary, -p #outputs just the predictions for each test instance, along with a range of one-based attribute ids (0 for none). Let's look at the following example. We shall assume soybean-train.arff and soybean-test.arff have been constructed via weka.filters.supervised.instance.StratifiedRemoveFolds as in a previous example.java weka.classifiers.bayes.NaiveBayes-K -t soybean-train.arff-T soybean-test.0 diaporthe-stem-canker 0.9999672587892333 diaporthe-stem-canker1 diaporthe-stem-canker 0.9999992614503429 diaporthe-stem-canker2 diaporthe-stem-canker 0.999998948559035 diaporthe-stem-canker3 diaporthe-stem-canker 0.9999998441238833 diaporthe-stem-canker4 diaporthe-stem-canker 0.9999989997681132 diaporthe-stem-canker5 rhizoctonia-root-rot 0.9999999395928124 rhizoctonia-root-rot6 rhizoctonia-root-rot 0.999998912860593 rhizoctonia-root-rot7 rhizoctonia-root-rot 0.9999994386283236 rhizoctonia-root-rot...The values in each line are separated by a single space. The fields are the zero-based test instance id, followed by the predicted class value, the confidence for the prediction (estimated probability of predicted class), and the true class. All these are correctly classified, so let's look at a few erroneous ones.32 phyllosticta-leaf-spot 0.7789710144361445 brown-spot...39 alternarialeaf-spot 0.6403333824349896 brown-spot...44 phyllosticta-leaf-spot 0.893568420641914 brown-spot...46 alternarialeaf-spot 0.5788190397739439 brown-spot...73 brown-spot 0.4943768155314637 alternarialeaf-spot...In each of these cases, a misclassification occurred, mostly between classes alternarialeaf-spot and brown-spot. The confidences seem to be lower than for correct classification, so for a real-life application it may make sense to output don't know below a certain threshold. WEKA also outputs a trailing newline.If we had chosen a range of attributes via -p, e.g. -p first-last, the mentioned attributes would have been output afterwards as comma-separated values, in (parantheses). However, the zero-based instance id in the first column offers a safer way to determine the test instances.Regrettably, -p does not work without test set (in versions before 3.5.8), i.e. for the cross-validation. Although patching WEKA is feasible, it is quite messy and has to be repeated for each new version. Another way to achieve this functionality is callClassifier, which calls WEKA functions from Java and implements this functionality, optionally outputting the complete class probablity distribution also. The output format is the same as above, but because of the cross-validation the instance ids are not in order, which can be remedied via|sort -n.If we had saved the output of -p in soybean-test.preds, the following call would compute the number of correctly classified instances:cat soybean-test.preds |awk'$2=$4&&$0!=""'|wc-lDividing by the number of instances in the test set, i.e. wc -l < soybean-test.preds minus one (= trailing newline), we get the training set accuracy.ExamplesUsually, if you evaluate a classifier for a longer experiment, you will do something like this (for csh): java -Xmx1024m weka.classifiers.trees.J48 -t data.arff -i-k-d J48-data.model >The -Xmx1024m parameter for maximum heap size ensures your task will get enough memory. There is no overhead involved, it just leaves more room for the heap to grow. -i and -k gives you some additional information, which may be useful, e.g. precision and recall for all classes. In case your model performs well, it makes sense to save it via -d-you can always delete it later! The implicit cross-validation gives a more reasonable estimate of the expected accuracy on unseen data than the training set accuracy. The output both of standard error and output should be redirected, so you get both errors and the normal output of your classifier. The last & starts the task in the background. Keep an eye on your task via top and if you notice the hard disk works hard all the time (for linux), this probably means your task needs too much memory and will not finish in time for the exam. ;-) In that case, switch to a faster classifier or use filters, e.g. for Resample to reduce the size of your dataset or StratifiedRemoveFolds to create training and test sets -for most classifiers, training takes more time than testing.So, now you have run a lot of experiments --which classifier is best? Trycat*.out |grep-A3"Stratified"|grep"^Correctly"...this should give you all cross-validated accuracies. If the cross-validated accuracy is roughly the same as the training set accuracy, this indicates that your classifiers is presumably not overfitting the training set.Now you have found the best classifier. To apply it on a new dataset, use e.g.java weka.classifiers.trees.J48 -l J48-data.model -T new-data.arffYou will have to use the same classifier to load the model, but you need not set any options. Just add the new test file via -T. If you want, -p first-last will output all test instances with classifications and confidence, followed by all attribute values, so you can look at each error separately.The following more complex csh script creates datasets for learning curves, i.e. creating a 75% training set and 25% test set from a given dataset, then successively reducing the test set by factor 1.2 (83%), until it is also 25% in size. All this is repeated thirty times, with different random reorderings (-S) and the results are written to different directories. The Experimenter GUI in WEKA can be used to design and run similar experiments.#!/bin/cshforeach f ($*)set run=1while($run<= 30)mkdir$run>&!/dev/nulljava weka.filters.supervised.instance.StratifiedRemoveFolds -N4-F1-S$run java weka.filters.supervised.instance.StratifiedRemoveFolds -N4-F1-S$run foreach nr (012345)set nrp1=$nr@nrp1++java weka.filters.supervised.instance.Resample -S0-Z83-c last-i$run/t endecho Run $run of $f done.@run++endend。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档