数据分析之鸢尾花KMEANS,层次,DBSCAN 聚类简单实现,评价指标:兰德系数,轮廓系数

  • Post author:
  • Post category:其他


import pandas as pd

import numpy as np

import seaborn as sns

import matplotlib.pyplot as plt

iris=pd.read_csv(“D:\Test\iris1.csv”)

iris.describe()

from sklearn.preprocessing import LabelEncoder

iris[“style”]=LabelEncoder().fit_transform(iris[“style”].values.reshape(-1,1))

from sklearn.preprocessing import StandardScaler

column_list=[“sl”,”sw”,”pl”,”pw”]

for i  in range(len(column_list)):

iris[column_list[i]]=StandardScaler().fit_transform(iris[column_list[i]].values.reshape(-1,1))

x=iris[[“sl”,”sw”,”pl”,”pw”]]

y=iris[“style”]

#KMeans聚类

from sklearn.cluster import KMeans

kmeans=KMeans(n_clusters=4)

kmeans.fit(x)

pre_label=kmeans.labels_

#print(pre_label)

x0=x[pre_label==0]

x1=x[pre_label&#



版权声明:本文为Aberton原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。