[英]Dendrogram fails to plot in R
I am doing Hierarchical Clustering in R following this tutorial . 我正在按照本教程在R中进行分层聚类。
My code is like this but it ends in an error: 我的代码是这样的,但是它以错误结尾:
> distances = dist(movies[2:20], method="euclidean")
> clusterMovies = hclust(distances, method="ward")
> plot(clusterMovies)
Error in plot.hclust(clusterMovies) : 'merge' matrix has invalid contents
It works OK for me... Be sure that you download the movieLens.txt
file with the exact way shown in the previous video of the tutorial, ie do not use 'Save as' and Internet Explorer . 它对我来说行得通...确保以本教程上一视频中显示的确切方式下载movieLens.txt
文件,即不要使用“另存为”和Internet Explorer 。 Then this should work: 然后这应该工作:
movies = read.table("movieLens.txt", header=FALSE, sep="|",quote="\"")
# Add column names
colnames(movies) = c("ID", "Title", "ReleaseDate", "VideoReleaseDate", "IMDB", "Unknown", "Action", "Adventure", "Animation", "Childrens", "Comedy", "Crime", "Documentary", "Drama", "Fantasy", "FilmNoir", "Horror", "Musical", "Mystery", "Romance", "SciFi", "Thriller", "War", "Western")
# Remove unnecessary variables
movies$ID = NULL
movies$ReleaseDate = NULL
movies$VideoReleaseDate = NULL
movies$IMDB = NULL
# Remove duplicates
movies = unique(movies)
# Compute distances
distances = dist(movies[2:20], method = "euclidean")
# Hierarchical clustering
clusterMovies = hclust(distances, method = "ward")
# Plot the dendrogram
plot(clusterMovies)
apart from a harmless warning message, after the clustermovies
command: 在clustermovies
命令之后,除了无害的警告消息clustermovies
:
The "ward" method has been renamed to "ward.D"; note new "ward.D2"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.