资源简介
Java机器学习实例源码,一共有10个源码示例,机器学习入门。
代码片段和文件信息
import java.util.ArrayList;
import cc.mallet.types.*;
import cc.mallet.classify.Classifier;
import cc.mallet.classify.ClassifierTrainer;
import cc.mallet.classify.NaiveBayesTrainer;
import cc.mallet.classify.Trial;
import cc.mallet.pipe.*;
import cc.mallet.pipe.iterator.*;
import java.util.regex.*;
import java.io.*;
public class SpamDetector {
public static void main(String[] args){
String stopListFilePath = “data/stoplists/en.txt“;
String dataFolderPath = “data/ex6DataEmails/train“;
String testFolderPath = “data/ex6DataEmails/test“;
ArrayList pipeList = new ArrayList();
pipeList.add(new Input2CharSequence(“UTF-8“));
Pattern tokenPattern = Pattern.compile(“[\\p{L}\\p{N}_]+“);
pipeList.add(new CharSequence2TokenSequence(tokenPattern));
pipeList.add(new TokenSequenceLowercase());
pipeList.add(new TokenSequenceRemoveStopwords(new File(stopListFilePath) “utf-8“ false false false));
pipeList.add(new TokenSequence2FeatureSequence());
pipeList.add(new FeatureSequence2FeatureVector());
pipeList.add(new Target2Label());
SerialPipes pipeline = new SerialPipes(pipeList);
FileIterator folderIterator = new FileIterator(
new File[] {new File(dataFolderPath)}
new TxtFilter()
FileIterator.LAST_DIRECTORY);
InstanceList instances = new InstanceList(pipeline);
instances.addThruPipe(folderIterator);
ClassifierTrainer classifierTrainer = new NaiveBayesTrainer();
Classifier classifier = classifierTrainer.train(instances);
InstanceList testInstances = new InstanceList(classifier.getInstancePipe());
folderIterator = new FileIterator(
new File[] {new File(testFolderPath)}
new TxtFilter()
FileIterator.LAST_DIRECTORY);
testInstances.addThruPipe(folderIterator);
Trial trial = new Trial(classifier testInstances);
System.out.println(“Accuracy: “ + trial.getAccuracy());
System.out.println(“F1 for class ‘spam‘: “ + trial.getF1(“spam“));
System.out.println(“Precision for class ‘“ +
classifier.getLabelAlphabet().lookupLabel(1) + “‘: “ +
trial.getPrecision(1));
System.out.println(“Recall for class ‘“ +
classifier.getLabelAlphabet().lookupLabel(1) + “‘: “ +
trial.getRecall(1));
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 126894 2016-04-26 13:55 MachineLearninginJava_Code\B03686_Software list.pdf
目录 0 2016-04-26 14:00 MachineLearninginJava_Code\Code\
文件 417 2016-04-03 07:21 MachineLearninginJava_Code\Code\.gitignore
目录 0 2016-04-26 13:44 MachineLearninginJava_Code\Code\MLJ-Chapter10\
文件 402 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\.classpath
文件 372 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\.project
目录 0 2016-04-26 13:44 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\
目录 0 2016-04-26 13:44 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\
目录 0 2016-04-26 13:43 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\
文件 2560 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\001.txt
文件 2252 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\002.txt
文件 1552 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\003.txt
文件 2412 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\004.txt
文件 1570 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\005.txt
文件 1187 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\006.txt
文件 1669 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\007.txt
文件 1922 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\008.txt
文件 1494 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\009.txt
文件 1449 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\010.txt
文件 1144 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\011.txt
文件 1847 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\012.txt
文件 1830 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\013.txt
文件 2981 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\014.txt
文件 3808 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\015.txt
文件 1393 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\016.txt
文件 1299 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\017.txt
文件 1002 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\018.txt
文件 1733 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\019.txt
文件 3854 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\020.txt
文件 2046 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\021.txt
文件 1933 2016-04-03 07:21 MachineLearninginJava_Code\Code\MLJ-Chapter10\data\bbc\business\022.txt
............此处省略3343个文件信息
相关资源
- 《Java入门经典》.(李伟张金辉).[
- 基于二维码的防伪项目java开发
- java解析lrc
- 基于数据库的自动化生成工具,自动
- java OA项目源代码
- 基于SSM的服装设计作品在线展销系统
- Java EE企业级应用开发教程Spring+Sprin
- JavaEE企业级应用SSM开发教程(PDF版)
- Undocumented Secrets of MATLAB-Java Programmin
- java8 中文文档
- 34个经典javaweb项目jsp学习
- jdk8 linux 64位 RPM安装包 java8 RPMRPMRP
- qtjambi-4.5.2开发包+qtjambi-eclipse插件.z
- jdk-8u101-windows-x64.rar
- javaweb酒店管理系统143891
- java人事管理系统143886
- 《架构探险——从零开始写javaweb框架
- Java开发大全(提高卷)
- 最新EffectiveJava中文版第3版.zip
- java万年历课程设计
- Java Swing界面.完美设计通讯录..有需要
- EffectiveJava中文版原书第3版_REV.pdf
- 2018黑马java.txt
- 面试官系统精讲Java源码及大厂真题
- java编程思想第五版附学习笔记.rar
- 小型超市管理系统JAVA课程设计报告
- 《数据结构与算法 Java版》 数据结构
- Java核心技术卷一基础知识第10版 PDF版
- Java项目 商城 和环境搭建连接
- SpringBoot Javaee颠覆者
评论
共有 条评论