hossam 0.4.15__py3-none-any.whl → 0.4.16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hossam/hs_plot.py CHANGED
@@ -22,7 +22,7 @@ from statsmodels.nonparametric.smoothers_lowess import lowess as sm_lowess
22
22
  from statannotations.Annotator import Annotator
23
23
 
24
24
  # ===================================================================
25
- from sklearn.cluster._kmeans import KMeans
25
+ from sklearn.cluster import AgglomerativeClustering, KMeans
26
26
 
27
27
  from sklearn.metrics import (
28
28
  mean_squared_error,
@@ -2559,7 +2559,7 @@ def distribution_plot(
2559
2559
 
2560
2560
 
2561
2561
  def silhouette_plot(
2562
- estimator: KMeans,
2562
+ estimator: KMeans | AgglomerativeClustering,
2563
2563
  data: DataFrame,
2564
2564
  title: str | None = None,
2565
2565
  width: int = config.width,
@@ -2574,7 +2574,7 @@ def silhouette_plot(
2574
2574
  군집분석 결과의 실루엣 플롯을 시각화함.
2575
2575
 
2576
2576
  Args:
2577
- estimator (KMeans): 학습된 KMeans 군집 모델 객체.
2577
+ estimator (KMeans | AgglomerativeClustering): 학습된 KMeans 또는 AgglomerativeClustering 군집 모델 객체.
2578
2578
  data (DataFrame): 군집분석에 사용된 입력 데이터 (n_samples, n_features).
2579
2579
  title (str, optional): 플롯 제목. None이면 자동 생성.
2580
2580
  width (int, optional): 플롯 가로 크기 (inch 단위).
@@ -2605,7 +2605,15 @@ def silhouette_plot(
2605
2605
  y_lower = 10
2606
2606
 
2607
2607
  # 클러스터링 갯수별로 fill_betweenx( )형태의 막대 그래프 표현.
2608
- for i in range(estimator.n_clusters): # type: ignore
2608
+ n_clusters: int = 0
2609
+ if hasattr(estimator, "n_clusters") and estimator.n_clusters is not None: # type: ignore
2610
+ n_clusters = estimator.n_clusters # type: ignore
2611
+ elif hasattr(estimator, "n_clusters_") and estimator.n_clusters_ is not None: # type: ignore
2612
+ n_clusters = estimator.n_clusters_ # type: ignore
2613
+ else:
2614
+ n_clusters = len(np.unique(estimator.labels_)) # type: ignore
2615
+
2616
+ for i in range(n_clusters): # type: ignore
2609
2617
  ith_cluster_sil_values = sil_values[estimator.labels_ == i] # type: ignore
2610
2618
  ith_cluster_sil_values.sort() # type: ignore
2611
2619
 
@@ -2626,18 +2634,18 @@ def silhouette_plot(
2626
2634
  ax.set_xlabel("The silhouette coefficient values") # type: ignore
2627
2635
  ax.set_ylabel("Cluster label") # type: ignore
2628
2636
  ax.set_xlim([-0.1, 1]) # type: ignore
2629
- ax.set_ylim([0, len(data) + (estimator.n_clusters + 1) * 10]) # type: ignore
2637
+ ax.set_ylim([0, len(data) + (n_clusters + 1) * 10]) # type: ignore
2630
2638
  ax.set_yticks([]) # type: ignore
2631
2639
  ax.set_xticks([0, 0.2, 0.4, 0.6, 0.8, 1]) # type: ignore
2632
2640
 
2633
2641
  if title is None:
2634
- title = "Number of Cluster : " + str(estimator.n_clusters) + ", Silhouette Score :" + str(round(sil_avg, 3)) # type: ignore
2642
+ title = "Number of Cluster : " + str(n_clusters) + ", Silhouette Score :" + str(round(sil_avg, 3)) # type: ignore
2635
2643
 
2636
2644
  finalize_plot(ax, callback, outparams, save_path, True, title) # type: ignore
2637
2645
 
2638
2646
 
2639
2647
  def cluster_plot(
2640
- estimator: KMeans | None = None,
2648
+ estimator: KMeans | AgglomerativeClustering | None = None,
2641
2649
  data: DataFrame | None = None,
2642
2650
  xname: str | None = None,
2643
2651
  yname: str | None = None,
@@ -2748,7 +2756,7 @@ def cluster_plot(
2748
2756
 
2749
2757
 
2750
2758
  def visualize_silhouette(
2751
- estimator: KMeans,
2759
+ estimator: KMeans | AgglomerativeClustering,
2752
2760
  data: DataFrame,
2753
2761
  xname: str | None = None,
2754
2762
  yname: str | None = None,
@@ -2765,7 +2773,7 @@ def visualize_silhouette(
2765
2773
  군집분석 결과의 실루엣 플롯과 군집 산점도를 한 화면에 함께 시각화함.
2766
2774
 
2767
2775
  Args:
2768
- estimator (KMeans): 학습된 KMeans 군집 모델 객체.
2776
+ estimator (KMeans | AgglomerativeClustering): 학습된 KMeans 또는 AgglomerativeClustering 군집 모델 객체.
2769
2777
  data (DataFrame): 군집분석에 사용된 입력 데이터 (n_samples, n_features).
2770
2778
  xname (str, optional): 산점도 x축에 사용할 컬럼명. None이면 첫 번째 컬럼 사용.
2771
2779
  yname (str, optional): 산점도 y축에 사용할 컬럼명. None이면 두 번째 컬럼 사용.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hossam
3
- Version: 0.4.15
3
+ Version: 0.4.16
4
4
  Summary: Hossam Data Helper
5
5
  Author-email: Lee Kwang-Ho <leekh4232@gmail.com>
6
6
  License-Expression: MIT
@@ -3,15 +3,15 @@ hossam/__init__.py,sha256=lJ-_g2HAmFnixOmKjCv7_cMSdiYwbM6SNlHEtptUlUI,4045
3
3
  hossam/hs_classroom.py,sha256=Sb1thy49LKn2zU90aiOVwHWhyWSMHLZbZX7eXmQlquc,27523
4
4
  hossam/hs_cluster.py,sha256=umgJRRr9vXkaFVIs6V_K3SrOo6Q5AEqVYmQSMaGj7rY,31945
5
5
  hossam/hs_gis.py,sha256=DVmndBK-_7GMK3J1_on3ieEQk1S0MfUZ8_wlX-cDdZQ,11581
6
- hossam/hs_plot.py,sha256=Xv5aBJ8PibAW9QP-cvv0mHM7MQkByNs0mZKArrDcWwY,94918
6
+ hossam/hs_plot.py,sha256=xE3blKlggntXqfAJpORYrxylmgwSQfG4Of2aBceF6t4,95515
7
7
  hossam/hs_prep.py,sha256=ypuX97mCxpo7CLoI_S79bUw7th0ok5LCZjt4vzRaGiI,38326
8
8
  hossam/hs_stats.py,sha256=MDS3rvaXDP8aYwcE36JTetWiZgE4fkXnNo0vwlXu-pA,119890
9
9
  hossam/hs_study.py,sha256=ZzL76_V0IHnk_YUTbWncIIBruOj2Sz3xs91snS6cpu0,2776
10
10
  hossam/hs_timeserise.py,sha256=NzGV4bJmVQr3qUFySOP25qENItmloYjgh3VgwSbSmXc,43163
11
11
  hossam/hs_util.py,sha256=ptl-2W7-0Ad_BemZMR8cFnDt6-SHCRRCk1Gh7giFjSs,16149
12
12
  hossam/leekh.png,sha256=1PB5NQ24SDoHA5KMiBBsWpSa3iniFcwFTuGwuOsTHfI,6395
13
- hossam-0.4.15.dist-info/licenses/LICENSE,sha256=nIqzhlcFY_2D6QtFsYjwU7BWkafo-rUJOQpDZ-DsauI,941
14
- hossam-0.4.15.dist-info/METADATA,sha256=XhcpBu7ZhjNeWCaPfJQxhmCj8IOHFqY0IJOX8SjJ_qk,3803
15
- hossam-0.4.15.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
16
- hossam-0.4.15.dist-info/top_level.txt,sha256=_-7bwjhthHplWhywEaHIJX2yL11CQCaLjCNSBlk6wiQ,7
17
- hossam-0.4.15.dist-info/RECORD,,
13
+ hossam-0.4.16.dist-info/licenses/LICENSE,sha256=nIqzhlcFY_2D6QtFsYjwU7BWkafo-rUJOQpDZ-DsauI,941
14
+ hossam-0.4.16.dist-info/METADATA,sha256=iMd8FAm4u9Q9dk6gI_b1jWhYNKGD3jnlQ9Gmb3v6kig,3803
15
+ hossam-0.4.16.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
16
+ hossam-0.4.16.dist-info/top_level.txt,sha256=_-7bwjhthHplWhywEaHIJX2yL11CQCaLjCNSBlk6wiQ,7
17
+ hossam-0.4.16.dist-info/RECORD,,