mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-29 05:57:23 +01:00
Refactor code for improved readability and consistency across multiple Jupyter notebooks
- Added missing commas in various print statements and function calls for better syntax. - Reformatted code to enhance clarity, including breaking long lines and aligning parameters. - Updated function signatures to use float type for sigma parameters instead of int for better precision. - Cleaned up comments and documentation strings for clarity and consistency. - Ensured consistent formatting in plotting functions and data handling.
This commit is contained in:
@@ -56,16 +56,15 @@
|
||||
"import seaborn as sns\n",
|
||||
"\n",
|
||||
"sns.set()\n",
|
||||
"import matplotlib.pyplot as plt # noqa: E402\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import plotly.express as px\n",
|
||||
"import plotly.graph_objects as gp\n",
|
||||
"from scipy.cluster.hierarchy import dendrogram, linkage # noqa: E402\n",
|
||||
"from scipy.cluster.hierarchy import dendrogram, linkage\n",
|
||||
"\n",
|
||||
"# Statistiques\n",
|
||||
"from scipy.stats import chi2_contingency # noqa: E402, F401\n",
|
||||
"from scipy.stats import chi2_contingency # noqa: F401\n",
|
||||
"\n",
|
||||
"# Machine Learning\n",
|
||||
"from sklearn.cluster import AgglomerativeClustering, KMeans # noqa: E402"
|
||||
"from sklearn.cluster import AgglomerativeClustering, KMeans"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -899,7 +898,9 @@
|
||||
"source": [
|
||||
"# Calcul de la partition de l'espace\n",
|
||||
"hierarchical_cluster = AgglomerativeClustering(\n",
|
||||
" n_clusters=3, metric=\"euclidean\", linkage=\"single\"\n",
|
||||
" n_clusters=3,\n",
|
||||
" metric=\"euclidean\",\n",
|
||||
" linkage=\"single\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"labels = hierarchical_cluster.fit_predict(data)\n",
|
||||
@@ -972,7 +973,9 @@
|
||||
"source": [
|
||||
"# Calcul de la partition de l'espace\n",
|
||||
"hierarchical_cluster = AgglomerativeClustering(\n",
|
||||
" n_clusters=3, metric=\"euclidean\", linkage=\"complete\"\n",
|
||||
" n_clusters=3,\n",
|
||||
" metric=\"euclidean\",\n",
|
||||
" linkage=\"complete\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"labels = hierarchical_cluster.fit_predict(data)\n",
|
||||
@@ -1482,7 +1485,7 @@
|
||||
"\n",
|
||||
"# Group by ZONE_RISQUE and aggregate the necessary columns\n",
|
||||
"data = data_retraitee.groupby([\"ZONE_RISQUE\"], as_index=False).agg(\n",
|
||||
" {\"NB\": \"sum\", \"CHARGE\": \"sum\", \"EXPO\": \"sum\"}\n",
|
||||
" {\"NB\": \"sum\", \"CHARGE\": \"sum\", \"EXPO\": \"sum\"},\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Calculate derived metrics\n",
|
||||
@@ -1547,7 +1550,11 @@
|
||||
"source": [
|
||||
"# Initialisation de l'algorithme\n",
|
||||
"kmeans_FREQ = KMeans(\n",
|
||||
" init=\"random\", n_clusters=5, n_init=1, random_state=42, max_iter=300\n",
|
||||
" init=\"random\",\n",
|
||||
" n_clusters=5,\n",
|
||||
" n_init=1,\n",
|
||||
" random_state=42,\n",
|
||||
" max_iter=300,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Transformation des données : plusieurs échantillons de 1 dimension\n",
|
||||
@@ -3559,7 +3566,11 @@
|
||||
"source": [
|
||||
"# Initialisation de l'algorithme\n",
|
||||
"kmeans_FREQ_CM = KMeans(\n",
|
||||
" init=\"random\", n_clusters=5, n_init=1, random_state=42, max_iter=300\n",
|
||||
" init=\"random\",\n",
|
||||
" n_clusters=5,\n",
|
||||
" n_init=1,\n",
|
||||
" random_state=42,\n",
|
||||
" max_iter=300,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Transformation des données : plusieurs échantillons de 1 dimension\n",
|
||||
@@ -4621,7 +4632,9 @@
|
||||
"source": [
|
||||
"# Calcul de la partition de l'espace\n",
|
||||
"hierarchical_cluster = AgglomerativeClustering(\n",
|
||||
" n_clusters=5, metric=\"euclidean\", linkage=\"single\"\n",
|
||||
" n_clusters=5,\n",
|
||||
" metric=\"euclidean\",\n",
|
||||
" linkage=\"single\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"labels = hierarchical_cluster.fit_predict(data_x)\n",
|
||||
@@ -5650,7 +5663,9 @@
|
||||
"source": [
|
||||
"# Calcul de la partition de l'espace\n",
|
||||
"hierarchical_cluster = AgglomerativeClustering(\n",
|
||||
" n_clusters=5, metric=\"euclidean\", linkage=\"single\"\n",
|
||||
" n_clusters=5,\n",
|
||||
" metric=\"euclidean\",\n",
|
||||
" linkage=\"single\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"labels = hierarchical_cluster.fit_predict(data_x)\n",
|
||||
|
||||
Reference in New Issue
Block a user