云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 《数据仓库与数据挖掘技术》-基于weka实现KNN

《数据仓库与数据挖掘技术》-基于weka实现KNN

  • 62 次阅读
  • 3 次下载
  • 2025/5/4 20:05:42

计算机与数据科学学院 《数据仓库与数据挖掘》实验报告

public Point(long id,double x, double y) { this.x = x; this.y = y; this.id = id; } public Point(long id,double x, double y, String type) { } }

this.x = x; this.y = y; this.type = type; this.id = id; public int getX() { // TODO Auto-generated method stub return 0; } public int getY() { // TODO Auto-generated method stub return 0; } public long getId() { // TODO Auto-generated method stub return 0; } public String getType() { // TODO Auto-generated method stub return null; } //get、set方法省略 计算机与数据科学学院 《数据仓库与数据挖掘》实验报告

public class Distance {

// 已知点id

private long id;

// 未知点id

private long nid;

// 二者之间的距离

private double disatance;

public Distance(long id, long nid, {

this.id = id;

this.nid = nid;

this.disatance = disatance;

}

//get、set方法省略

double) disatance 计算机与数据科学学院 《数据仓库与数据挖掘》实验报告

public int getDisatance() { // TODO Auto-generated method stub return 0; } }

public class CompareClass implements Comparator{

public int compare(Distance d1, Distance d2) {

return d1.getDisatance()>d2.getDisatance()?20 : -1;

} } // 一、输入所有已知点

List dataList = creatDataSet(); // 二、输入未知点

Point x = new Point(5, 1.2, 1.2);

// 三、计算所有已知点到未知点的欧式距离,并根据距离对所有已知点排序

CompareClass compare = new CompareClass(); Set distanceSet = new TreeSet(compare)

for ( Point point : dataList ) { distanceSet.add(new Distance(point.getId(), x.getId(), oudistance(point, x))); }

计算机与数据科学学院 《数据仓库与数据挖掘》实验报告

// 四、选取最近的k个点 double k = 5; /**

* 五、计算k个点所在分类出现的频率 */

// 1、计算每个分类所包含的点的个数 List distanceList= new ArrayList(distanceSet); Map map =

getNumberOfType(distanceList, dataList, k); // 2、计算频率

Map p = computeP(map, k);

x.setType(maxP(p)); System.out.println(\未知点的类型为:\+x.getType()); }

// 欧式距离计算

public static double oudistance (Point point1, Point point2) {

double temp = Math.pow(point1.getX() - point2.getX(), 2)

+ Math.pow(point1.getY() - point2.getY(), 2); return Math.sqrt(temp); }

// 找出最大频率

public static String maxP(Map map) { String key = null; double value = 0.0;

for (Map.Entry entry : map.entrySet()) {

if (entry.getValue() > value) { key = entry.getKey();

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

计算机与数据科学学院 《数据仓库与数据挖掘》实验报告 public Point(long id,double x, double y) { this.x = x; this.y = y; this.id = id; } public Point(long id,double x, double y, String type) { } } this.x = x; this.y = y; this.type = type;

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com