Created
October 4, 2018 02:22
-
-
Save monmonmon/21d59d16c404f87d0417548326c01803 to your computer and use it in GitHub Desktop.
Team AI のデータハッカソンで Kaggle UFO Sightings に1時間程度で挑戦
This file contains 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
#!/usr/bin/env python | |
# UFO Sightings | Kaggle | |
# https://www.kaggle.com/NUFORC/ufo-sightings | |
# NASA/Space Data Hackathon(宇宙デー( タ分析ハッカソン) | Meetup | |
# https://www.meetup.com/ja-JP/Machine-Learning-Meetup-by-team-ai/events/254436043 | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
ds = pd.read_csv('scrubbed.csv') | |
ds['datetime'] = pd.to_datetime(ds['datetime'], errors='coerce') | |
# 年別のUFO観測件数をグラフにプロット | |
ds['year'] = ds['datetime'].map(lambda x: x.year) | |
yy = ds['year'].value_counts().reset_index() | |
yy = yy.sort_values(by='index') | |
plt.plot(yy['index'], yy['year']) | |
plt.show() | |
# 月別のUFO観測件数をグラフにプロット | |
ds['month'] = ds['datetime'].map(lambda x: x.month) | |
mm = ds['month'].value_counts().reset_index() | |
mm = mm.sort_values(by='index') | |
plt.plot(mm['index'], mm['month']) | |
plt.show() | |
# 国ごと (us, ca, gb, au, de, na) の月別のUFO観測件数をグラフにプロット | |
from sklearn.preprocessing import StandardScaler | |
countries = ds['country'].fillna('na').unique() | |
for country in countries: | |
cc = ds[ ds['country'] == country ] | |
cc['month'] = cc['datetime'].map(lambda x: x.month) | |
hoge = cc['month'].value_counts().reset_index().sort_values(by='index') | |
plt.plot(hoge['index'], hoge['month'], label=country) | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment