帝王谷资源网 Design By www.wdxyy.com

本文实例为大家分享了Python实点云分割k-means(sklearn),供大家参考,具体内容如下

python实点云分割k-means(sklearn)详解

python实点云分割k-means(sklearn)详解

植物叶片分割

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
from mpl_toolkits.mplot3d import Axes3D
data = pd.read_csv("jiaaobo1.txt",sep = " ")

data1 = data.iloc[:,0:3]

#标准化
transfer = StandardScaler()
data_new = transfer.fit_transform(data1)
data_new
#预估计流程
estimator = KMeans(n_clusters = 10)
estimator.fit(data_new)
y_pred = estimator.predict(data_new)
#也可以不预测
#cluster = KMeans(n_clusters = 9).fit(data_new)
#y_pred = cluster.labels_s
#质心 
#centroid = cluster.cluster_centers_
#centroid.shape

fig = plt.figure()
ax = Axes3D(fig)
for i in range(9):
  ax.scatter3D(data_new[y_pred == i,0],data_new[y_pred == i,1],data_new[y_pred == i,2],marker = ".")
ax.view_init(elev = 60,azim = 30)
ax.set_zlabel('Z')
ax.set_ylabel('Y')
ax.set_xlabel('X')
plt.show()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
python,分割,k-means

帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com