M2_SETI/D3/TP/Cours.ipynb
2023-01-29 16:56:40 +01:00

128 lines
2.6 KiB
Text

{
"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",
"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.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)]"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "2ef431f6525756fa8a44688585fa332ef3b2e5fcfe8fe75df35bbf7028a8b511"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}