Вы не можете выбрать более 25 тем
Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
24 строки
790 B
Python
24 строки
790 B
Python
import numpy as np
|
|
from matplotlib import pyplot as plt
|
|
import pandas as pd
|
|
from sklearn.datasets import load_iris
|
|
from sklearn.cluster import KMeans
|
|
|
|
|
|
iris = load_iris()
|
|
iris_pd=pd.DataFrame(data=np.c_[iris['data']], columns=iris['feature_names'])
|
|
data = iris_pd[['petal length (cm)', 'petal width (cm)', 'sepal length (cm)']].to_numpy()
|
|
|
|
|
|
model = KMeans(n_clusters=2, random_state=0, n_init="auto").fit(data)
|
|
|
|
|
|
fig1 = plt.figure()
|
|
ax = plt.axes(projection='3d')
|
|
ax.scatter3D(iris_pd['petal length (cm)'], iris_pd['petal width (cm)'], iris_pd['sepal length (cm)'], c = model.labels_, cmap='tab10')
|
|
ax.set_title('K-means Method \n n_clusters=2')
|
|
ax.set_xlabel('petal length (cm)')
|
|
ax.set_ylabel('petal width (cm)')
|
|
ax.set_zlabel('sepal length (cm)')
|
|
|
|
plt.show() |