-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModis_Cluster.py
More file actions
32 lines (27 loc) · 1021 Bytes
/
Modis_Cluster.py
File metadata and controls
32 lines (27 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# coding:utf-8
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.cluster import KMeans
from mpl_toolkits.mplot3d import Axes3D
import Common_func
import os
root_path = Common_func.UsePlatform()
data_path = os.path.join(root_path,'staion-grid-withlanlon-data-.csv')
data = pd.read_csv(data_path)
data = data[(data['grid_value'] < 500) & (data['station_value'] < 500) & (data['grid_value'] > 0) & (
data['station_value'] > 0)]
cluster_feature = data[['grid_value', 'station_value', 'Elevation']].values
#print (cluster_feature)
kmeans = KMeans(n_clusters= 2, random_state= 0).fit(cluster_feature)
#print (kmeans.cluster_centers_)
fig = plt.figure()
ax = Axes3D(fig)
labels = kmeans.labels_
ax.scatter(cluster_feature[:, 0], cluster_feature[:, 1], cluster_feature[:, 2],
c=labels.astype(np.float), edgecolor='k')
ax.set_xlabel('grid_value')
ax.set_ylabel('station_value')
ax.set_zlabel('Elevation')
fig.show()