import pandas as pd
import numpy as np

%matplotlib inline
import matplotlib.pyplot as plt

# read the data and set the datetime as the index
import zipfile
with zipfile.ZipFile('../datasets/bikeshare.csv.zip', 'r') as z:
    f = z.open('bikeshare.csv')
    bikes = pd.read_csv(f, index_col='datetime', parse_dates=True)

# "count" is a method, so it's best to name that column something else
bikes.rename(columns={'count':'total'}, inplace=True)

bikes.head()

"""
Explanation: Exercise 04
Estimate a regression using the Capital Bikeshare data
Forecast use of a city bikeshare system
We'll be working with a dataset from Capital Bikeshare that was used in a Kaggle competition (data dictionary).
Get started on this competition through Kaggle Scripts
Bike sharing systems are a means of renting bicycles where the process of obtaining membership, rental, and bike return is automated via a network of kiosk locations throughout a city. Using these systems, people are able rent a bike from a one location and return it to a different place on an as-needed basis. Currently, there are over 500 bike-sharing programs around the world.
The data generated by these systems makes them attractive for researchers because the duration of travel, departure location, arrival location, and time elapsed is explicitly recorded. Bike sharing systems therefore function as a sensor network, which can be used for studying mobility in a city. In this competition, participants are asked to combine historical usage patterns with weather data in order to forecast bike rental demand in the Capital Bikeshare program in Washington, D.C.
End of explanation
"""


bikes.shape

"""
Explanation: datetime - hourly date + timestamp  
season -  
1 = spring
2 = summer 
3 = fall 
4 = winter 
holiday - whether the day is considered a holiday
workingday - whether the day is neither a weekend nor holiday
weather - 
1: Clear, Few clouds, Partly cloudy, Partly cloudy 
2: Mist + Cloudy, Mist + Broken clouds, Mist + Few clouds, Mist 
3: Light Snow, Light Rain + Thunderstorm + Scattered clouds, Light Rain + Scattered clouds 
4: Heavy Rain + Ice Pallets + Thunderstorm + Mist, Snow + Fog 
temp - temperature in Celsius
atemp - "feels like" temperature in Celsius
humidity - relative humidity
windspeed - wind speed
casual - number of non-registered user rentals initiated
registered - number of registered user rentals initiated
total - number of total rentals
End of explanation
"""


# Pandas scatter plot
bikes.plot(kind='scatter', x='temp', y='total', alpha=0.2)

"""
Explanation: Exercise 4.1
What is the relation between the temperature and total?
For a one percent increase in temperature how much the bikes shares increases?
Using sklearn estimate a linear regression and predict the total bikes share when the temperature is 31 degrees
End of explanation
"""


