Unsupervised Learning ใน Python
Benjamin Wilson
Director of Research at lateral.io
species setosa versicolor virginica
labels
0 0 2 36
1 50 0 0
2 0 48 14
pandasspeciesprint(species)
['setosa', 'setosa', 'versicolor', 'virginica', ... ]
import pandas as pd
df = pd.DataFrame({'labels': labels, 'species': species})
print(df)
labels species
0 1 setosa
1 1 setosa
2 2 versicolor
3 2 virginica
4 1 setosa
...
ct = pd.crosstab(df['labels'], df['species'])
print(ct)
species setosa versicolor virginica
labels
0 0 2 36
1 50 0 0
2 0 48 14
ถ้าไม่มีข้อมูลสายพันธุ์ จะประเมินการจัดกลุ่มได้อย่างไร?
ใช้เพียงตัวอย่างและ label ของกลุ่ม
การจัดกลุ่มที่ดีมีกลุ่มที่กระชับ
ตัวอย่างในแต่ละกลุ่มอยู่ใกล้กัน
fit() เข้าถึงได้ผ่าน attribute inertia_from sklearn.cluster import KMeans
model = KMeans(n_clusters=3)
model.fit(samples)
print(model.inertia_)
78.9408414261


Unsupervised Learning ใน Python