齐勇cn

# Exercise 10: Hierarchical clustering of the grain data

In the video, you learnt that the SciPy `linkage()` function performs hierarchical clustering on an array of samples. Use the `linkage()` function to obtain a hierarchical clustering of the grain samples, and use `dendrogram()` to visualize the result. A sample of the grain measurements is provided in the array `samples`, while the variety of each grain sample is given by the list `varieties`.

From the course Transition to Data Science. Buy the entire course for just \$10 for many more exercises and helpful video lectures.

Step 1: Load the dataset (done for you).

In [1]:
``````import pandas as pd

# remove the grain species from the DataFrame, save for later
varieties = list(seeds_df.pop('grain_variety'))

# extract the measurements as a NumPy array
samples = seeds_df.values``````

Step 2: Import:

• `linkage` and `dendrogram` from `scipy.cluster.hierarchy`.
• `matplotlib.pyplot` as `plt`.

In [2]:

``````from scipy.cluster.hierarchy import linkage, dendrogram
import matplotlib.pyplot as plt``````

Step 3: Perform hierarchical clustering on `samples` using the `linkage()` function with the `method='complete'` keyword argument. Assign the result to `mergings`.

In [3]:

`mergings = linkage(samples, method='complete')`

Step 4: Plot a dendrogram using the `dendrogram()` function on `mergings`, specifying the keyword arguments `labels=varieties`, `leaf_rotation=90`, and `leaf_font_size=6`. Remember to call `plt.show()` afterwards, to display your plot.

In [4]:
``````dendrogram(mergings,
labels=varieties,
leaf_rotation=90,
leaf_font_size=6,
)
plt.show()``````

### 齐勇cn

【opencv】图形的绘制

1.矩形图像的绘制： 原函数：void cvRectangle(CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int line_type=8,int shift=0) img就是需要绘制的图像 pt1 and pt......

2014/10/08
1.2K
1
opm-server-mirror

luosheng86
2013/01/29
1K
0
Javascript图元绘制库--ternlight

fancimage1
2013/02/07
6.3K
1
Python开发者社区整站源码--Pythoner

pythoner.net 整站源代码 依赖模块 Django 1.4.2 PIL DjangoVerifyCode 0.2.2 开发环境配置 运行scripts目录下的setupenv.sh文件，将会自动安装配置所需环境 设置本地环境变量:export env=D...

~T.y~
2013/04/10
3.2K
0

2012/10/28
2.2K
0

osc_emgrwx5d
5分钟前
0
0

osc_7owgvpdx
6分钟前
0
0
dockerfile源码编译安装nginx、php和harbor

osc_otuqqtuq
7分钟前
0
0

Dynamsoft Barcode Readerv7.5带来了一些新的参数配置，例如中心定位条形码、二值化模式等。让我们来看看新功能中的一些亮点。 更新 添加了对QR Code Model 1（QR Code规范的旧版本）的支持。...

roffey
8分钟前
6
0
TCP端口的十一种连接状态

TCP端口的十一种连接状态∶ CLOSED∶端口默认是关闭状态。  LISTEN∶服务器程序开始监听一个端口，就是LISTEN状态。     SYN_RCVD∶三次握手的第二次握手后的端口状态，是收到了客户端发...

8分钟前
0
0