导航:首页 > 数据分析 > 什么数据适用于r型聚类分析

什么数据适用于r型聚类分析

发布时间:2023-07-22 11:17:22

㈠ 聚类分析中常见的数据类型有哪些

聚类分析,又称群分析,即建立一种分类方法:将一批样品或者指标(变量),按照它们在性质上的亲疏、相似程度进行分类。
按其聚类的方法,数据类型有以下六种:
系统聚类分析:开始每个对象自成一类,然后将最相似的两类合并,合并过后重新计算新类与其它类的距离或相近性程度。这一过程一直继续下去直到所有的对象归为一类为止

②调优法(动态聚类法):首先对n个对象进行初步分类,然后根据分类的损失函数尽可能小的原则对其进行调整,直到分类合理为止;
③最优分割法(有序样品聚类法):开始将所有样品看成一类,然后根据某种最优准则将他们分割为二类、三类,一直分割到所需要的K类为止;
④模糊聚类法:利用模糊集理论来处理分类的问题,他将经济领域中最有模糊特征的两态数据或多态数据具有明显的分类效果;
⑤图论据类法:利用图论中最小支撑树的概念来处理分类问题;
⑥聚类预报法:聚类预报弥补了回归分析和判别分析的不足。
按分类对象的不同:聚类分为R型和Q型

㈡ R语言学习笔记之聚类分析

R语言学习笔记之聚类分析

使用k-means聚类所需的包:

factoextra

cluster#加载包

library(factoextra)

library(cluster)l

#数据准备
使用内置的R数据集USArrests

#load the dataset

data("USArrests")

#remove any missing value (i.e, NA values for not available)

#That might be present in the data

USArrests <- na.omit(USArrests)#view the first 6 rows of the data

head(USArrests, n=6)

在此数据集中,列是变量,行是观测值
在聚类之前我们可以先进行一些必要的数据检查即数据描述性统计,如平均值、标准差等

desc_stats <- data.frame( Min=apply(USArrests, 2, min),#minimum

Med=apply(USArrests, 2, median),#median

Mean=apply(USArrests, 2, mean),#mean

SD=apply(USArrests, 2, sd),#Standard deviation

Max=apply(USArrests, 2, max)#maximum

)

desc_stats <- round(desc_stats, 1)#保留小数点后一位head(desc_stats)

变量有很大的方差及均值时需进行标准化

df <- scale(USArrests)

#数据集群性评估
使用get_clust_tendency()计算Hopkins统计量

res <- get_clust_tendency(df, 40, graph = TRUE)

res$hopkins_stat

## [1] 0.3440875

#Visualize the dissimilarity matrix

res$plot

Hopkins统计量的值<0.5,表明数据是高度可聚合的。另外,从图中也可以看出数据可聚合。

#估计聚合簇数
由于k均值聚类需要指定要生成的聚类数量,因此我们将使用函数clusGap()来计算用于估计最优聚类数。函数fviz_gap_stat()用于可视化。

set.seed(123)

## Compute the gap statistic

gap_stat <- clusGap(df, FUN = kmeans, nstart = 25, K.max = 10, B = 500)

# Plot the result

fviz_gap_stat(gap_stat)

图中显示最佳为聚成四类(k=4)

#进行聚类

set.seed(123)

km.res <- kmeans(df, 4, nstart = 25)

head(km.res$cluster, 20)

# Visualize clusters using factoextra

fviz_cluster(km.res, USArrests)

#检查cluster silhouette图

Recall that the silhouette measures (SiSi) how similar an object ii is to the the other objects in its own cluster versus those in the neighbor cluster. SiSi values range from 1 to - 1:

A value of SiSi close to 1 indicates that the object is well clustered. In the other words, the object ii is similar to the other objects in its group.

A value of SiSi close to -1 indicates that the object is poorly clustered, and that assignment to some other cluster would probably improve the overall results.

sil <- silhouette(km.res$cluster, dist(df))

rownames(sil) <- rownames(USArrests)

head(sil[, 1:3])

#Visualize

fviz_silhouette(sil)

图中可以看出有负值,可以通过函数silhouette()确定是哪个观测值

neg_sil_index <- which(sil[, "sil_width"] < 0)

sil[neg_sil_index, , drop = FALSE]

## cluster neighbor sil_width

## Missouri 3 2 -0.07318144

#eclust():增强的聚类分析

与其他聚类分析包相比,eclust()有以下优点:

简化了聚类分析的工作流程

可以用于计算层次聚类和分区聚类

eclust()自动计算最佳聚类簇数。

自动提供Silhouette plot

可以结合ggplot2绘制优美的图形

#使用eclust()的K均值聚类

# Compute k-means

res.km <- eclust(df, "kmeans")

# Gap statistic plot

fviz_gap_stat(res.km$gap_stat)

# Silhouette plotfviz_silhouette(res.km)

## cluster size ave.sil.width

## 1 1 13 0.31

## 2 2 29 0.38

## 3 3 8 0.39

#使用eclust()的层次聚类

# Enhanced hierarchical clustering

res.hc <- eclust(df, "hclust") # compute hclust

fviz_dend(res.hc, rect = TRUE) # dendrogam

#下面的R代码生成Silhouette plot和分层聚类散点图。

fviz_silhouette(res.hc) # silhouette plot

## cluster size ave.sil.width

## 1 1 19 0.26

## 2 2 19 0.28

## 3 3 12 0.43

fviz_cluster(res.hc) # scatter plot

#Infos

This analysis has been performed using R software (R version 3.3.2)

阅读全文

与什么数据适用于r型聚类分析相关的资料

热点内容
excel表格文件化乱码 浏览:986
win7无法打开隐藏文件 浏览:757
怎样把压缩文件变成空白文件 浏览:516
wokrNC和UG编程哪个好 浏览:487
爱奇艺随刻文件名 浏览:40
wps是怎么压缩文件 浏览:986
dos配置文件名 浏览:582
java软件工程师做什么 浏览:897
3dmax导出ive文件 浏览:464
数据重复性好是什么意思 浏览:166
如何查找电脑文件使用历史记录 浏览:821
linux可以运行exe的文件吗 浏览:935
库币是哪个国家的app 浏览:201
大智慧internet文件夹有哪些文件 浏览:89
编程培训课程哪个排名好 浏览:124
我的cad怎么没显示文件选项卡 浏览:952
命令行当前是哪个数据库 浏览:588
为什么appstore打开空白 浏览:574
选货车软件什么app最好 浏览:577
psv仙境传说ace如何降级版本 浏览:460

友情链接