You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
2.5 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Cours D3\n",
"\n",
"## Cours Méthodes d'analyse non supervisées\n",
"\n",
"Exemple de clustering complete linkage :\n",
"On prend 4 singletons avec leur matrice de dissimilarité."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0. 0.3 0.4 0.8 ]\n",
" [0.3 0. 0.5 0.8 ]\n",
" [0.4 0.5 0. 0.45]\n",
" [0.8 0.8 0.45 0. ]]\n"
]
}
],
"source": [
"D = np.array([[0, 0.3, 0.4, 0.7],[0, 0, 0.5, 0.8],[0, 0, 0, 0.45],[0, 0, 0, 0]])\n",
"D += D.T\n",
"print(D)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On link les 2 clusters les plus proches (a,b) donc on prend le max de différence entre (a,b) et c et d."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0. 0.5 0.8 ]\n",
" [0.5 0. 0.45]\n",
" [0.8 0.45 0. ]]\n"
]
}
],
"source": [
"D2 = np.array([[0, 0.5, 0.8],[0.5, 0, 0.45],[0.8, 0.45, 0]])\n",
"print(D2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On coupe au saut le plus important sur le dendrogramme (on continu jusqu'a avoir K-clusters)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0. 0.8]\n",
" [0.8 0. ]]\n"
]
}
],
"source": [
"# (a,b,c) et d\n",
"D3 = np.array([[0, 0.8],[0.8,0]])\n",
"print(D3)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.10 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}