资源简介
用MapReduce实现KMeans算法,数据的读写都是在HDFS上进行的,在伪分布下运行没有问题。文档中有具体说明。

代码片段和文件信息
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
public class CenterInitial {
public void run(String[] args) throws IOException
{
String[] clist;
int k = 10;
String string = ““;
String inpath = args[0]+“/cluster“; //cluster
String outpath = args[1]+“/center“; //center
Configuration conf1 = new Configuration(); //读取hadoop文件系统的配置
conf1.set(“hadoop.job.ugi“ “hadoophadoop“);
FileSystem fs = FileSystem.get(URI.create(inpath)conf1); //FileSystem是用户操作HDFS的核心类,它获得URI对应的HDFS文件系统
FSDataInputStream in = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
try{
in = fs.open( new Path(inpath) );
IOUtils.copyBytes(inout50false); //用Hadoop的IOUtils工具方法来让这个文件的指定字节复制到标准输出流上
clist = out.toString().split(“ “);
} finally {
IOUtils.closeStream(in);
}
FileSystem filesystem = FileSystem.get(URI.create(outpath) conf1);
for(int i=0;i {
int j=(int) (Math.random()*100) % clist.length;
if(string.contains(clist[j])) // choose the same one
{
k++;
continue;
}
string = string + clist[j].replace(“ “ ““) + “ “;
}
OutputStream out2 = filesystem.create(new Path(outpath) );
IOUtils.copyBytes(new ByteArrayInputStream(string.getBytes()) out2 4096true); //write string
System.out.println(string);
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2533 2012-06-19 08:31 KMeans\.classpath
文件 417 2012-06-19 08:31 KMeans\.project
文件 2972 2012-06-19 08:38 KMeans\bin\CenterInitial.class
文件 4558 2012-06-19 10:09 KMeans\bin\KMapper.class
文件 2508 2012-06-19 10:34 KMeans\bin\KMeans.class
文件 3445 2012-06-19 10:06 KMeans\bin\KReducer.class
文件 3306 2012-06-19 10:31 KMeans\bin\NewCenter.class
文件 1741 2012-06-19 08:38 KMeans\src\CenterInitial.java
文件 2278 2012-06-19 10:09 KMeans\src\KMapper.java
文件 1385 2012-06-19 10:34 KMeans\src\KMeans.java
文件 1051 2012-06-19 10:06 KMeans\src\KReducer.java
文件 1767 2012-06-19 10:31 KMeans\src\NewCenter.java
文件 371 2012-06-20 21:49 KMeans\说明.txt
..AD... 0 2012-06-19 10:08 KMeans\bin
..AD... 0 2012-06-20 21:49 KMeans\src
..AD... 0 2012-06-20 21:49 KMeans
----------- --------- ---------- ----- ----
28332 16
相关资源
- SpringBoot+H2+mybatis-plus59130
- 登录注册界面.zip48872
- 数字华容道
- SSM+Shiro+redis实现单点登陆
- jstl-api-1.2和jstl-impl-1.2
- 基于MVC模式的会员管理系统
- 国内一家大型软件公司内部的正规软
- 仿windows记事本
- GUI银行管理系统
- 超市收银系统eclipse access大学课程设计
- 模拟ATM柜员机系统--连接数据库
- A*算法的2D演示(带源码)
- 代码审查表和代码审查实例
- 仿126 网易 163 邮箱 界面
- Tomcat6.x
- 简单的行编辑器
- 扫雷(MVC架构)
- 302 Found
- window ping命令加时间并记录日志
- springboot+rabbitmq项目demo(亲测可正常运
- jxbrowser 所有版本通用的破解包
- 2017年-传智播客-张志君老师-SpringBoo
- Blob.js+Export2Excel.js
- 机会路由源代码+仿真工具(SCORP)
- POI中文帮助文档附带api手册.zip
- 2018双十一阿里供应链服务平台讲座
- 原银在线信贷平台概要设计说明书v
- office_word_api 开发文档
- sun.misc.Unsafe源码
- netty的视频90集
评论
共有 条评论