train = pd.read_csv('train.csv')
train.head()

"""
Explanation: Read data
End of explanation
"""


model = ExtraTreesRegressor()

"""
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
count - number of total rentals

Build a model
End of explanation
"""


X = train[ ['season', 'holiday', 'workingday', 'weather', 'temp', 'atemp', 'humidity', 'windspeed'] ].values
y = train['count'].values

model.fit(X, y)

"""
Explanation: train
Prepare two things:
X - features. Matrix.
y - target variable. Vector.
End of explanation
"""


def rmsle(y_true, y_pred):
    diff = np.log(y_pred + 1) - np.log(y_true + 1)
    mean_error = np.square(diff).mean()
    return np.sqrt(mean_error)

scorer = make_scorer(rmsle, greater_is_better=False)

y_pred = model.predict(X)
rmsle(y, y_pred)

"""
Explanation: Evoluation a model
$$ \sqrt{\frac{1}{n} \sum_{i=1}^n (\log(p_i + 1) - \log(a_i+1))^2 }$$
where
n is the number of hours in the test set
pi is your predicted count
ai is the actual count
log(x) is the natural logarithm
End of explanation
"""


