클러스터링 ) 연속형 범주형 변수 둘 다 고려한 알고리즘 살펴보기

2021. 5. 8. 16:09ML(머신러닝)/Clustering

728x90

 

 

installation

pip install kmodes

Implemented are:

클러스트 $l$ 에서 발생하는 $c_j$ 값이 나오는 확률값을 의미한다. 

어떤 클러스트 l에서 $c_j$가 나올 확률이 낮게 나올 수록 loss가 커진다는 의미인 것 같은데, 왜 이게 loss로 가는 지 아직은 잘 이해가 안된다...

추후에 좀 더 알아보도록 하자!!

 

예제

import numpy as np
from sklearn import datasets
from kmodes.kprototypes import KPrototypes
import matplotlib.pyplot as plt
import plotly.express as px
import pandas as pd
###
iris = datasets.load_iris()
data = np.c_[iris['data'], iris['target']]
kp = KPrototypes(n_clusters=3, init='Huang', n_init=1, verbose=True)
kp.fit_predict(data, categorical=[4])

 

시각화

np_arr = np.concatenate((iris["data"],iris["target"].reshape(-1,1), kp.labels_.reshape(-1,1)),axis=1)
df = pd.DataFrame(np_arr , columns = ["1","2","3","4","target","cluster"])
df[["cluster","target"]] = df[["cluster","target"]].astype(object)
px.scatter(df , x="1",y="2",color="target",symbol="cluster",width=700,height=700)

plotly simple code

<div id="graph">
    <script>
    	Plotly.plot('graph',
        	### 여기에 json 넣기 ###
        , {});
    </script>
</div>

 

visualization

분류 결과를 봤을 때, 한가지 클래스 말고는 잘 분류한 것을 알 수 있었다.

추후 카테고리 데이터랑 미싱 데이터 같은 것도 테스트 해볼 예정이다. 

 

 
 
 

 

 

 

http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.94.9984 

 

CiteSeerX — Clustering large data sets with mixed numeric and categorical values

 

citeseerx.ist.psu.edu


https://link.medium.com/fOVbR3gm5fb

 

Clustering Algorithm for data with mixed Categorical and Numerical features

Clustering is an unsupervised machine learning technique that devices the population into several clusters or groups in such a way that data points in a cluster are similar to each other, and data…

towardsdatascience.com


항상 궁금했던 연속형과 범주형이 같이 있을 때 어떤식으로 거리를 평가하는 지가 궁금한데 이 글을 통해 감을 얻을 수 있으면 좋겠다.

 

 

 

https://github.com/nicodv/kmodes

 

nicodv/kmodes

Python implementations of the k-modes and k-prototypes clustering algorithms, for clustering categorical data - nicodv/kmodes

github.com

 

728x90