Created
December 9, 2017 13:40
-
-
Save xhiroga/d929e8fbdb0bda4b9fae6bca2a9bb284 to your computer and use it in GitHub Desktop.
世界中のUFO目撃情報をk-mean法でクラスタリング
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
from sklearn import cluster, datasets | |
import pandas as pd | |
import numpy as np | |
from matplotlib import pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
# このデータが曲者で、数値データの中に英字や記号が混ざってた | |
df = pd.read_csv("scrubbed.csv") | |
df__ = df.iloc[:,[5,9,10]].values.astype('float32') | |
fig = plt.figure() | |
ax = Axes3D(fig) | |
#まずは元データをプロット | |
#ax.scatter(df_.T[0,::1000], df_.T[1,::1000], df_.T[2,::1000]) | |
#plt.show() | |
km = cluster.KMeans(n_clusters=5) | |
km.fit(df__) | |
colors = ["r","g","b","c","m"] | |
for i in range(300): | |
ax.scatter(df__[i,0],df__[i,1],df__[i,2],c=colors[km.labels_[i]]) | |
ax.set_xlabel(df.columns[5]) | |
ax.set_ylabel(df.columns[9]) | |
ax.set_zlabel(df.columns[10]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment