Bike Sharing Demand
Day 1
- Ridge : 1.04966
- Lasso : 1.04126
- Random Forest : 0.43310
- Gradient Boosting : 0.42744
- 535๋ฑ (Top 15%)
Score : 0.42744 Rank : 535 (Top 16.49%)
Day 2
Model์ train ์ํฌ ๋, ํ์์ฒ๋ผ sklearn์ train_test_split์ ์ฌ์ฉํ๋๋ฐ, ์๊ฐํด๋ณด๋ time series ๋ฐ์ดํฐ๋ฅผ ์ด๋ฐ์์ผ๋ก split ํ๋ฉด ๋ฌธ์ ๊ฐ ์์ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ ํ๊ณ ์ฝ๋๋ฅผ ์์ ํ๊ธฐ๋ก ํ๋ค.
๋ฐฉ๋ฒ1 - ์๊ฐ์์ผ๋ก ์ ๋ ฌ ํ ์์์๋ถํฐ 80%๋งํผ์ train ๋ฐ์ดํฐ์ ์ผ๋ก, ๋๋จธ์ง 20%๋ฅผ validation ๋ฐ์ดํฐ์ ์ผ๋ก ์ค์ ํ๋ค.
- Ridge : 1.04723 (+0.23%)
- Lasso : 1.05059 (-0.89%)
- Random Forest : 0.41850 (+3.38%)
- Gradient Boosting : 0.43600 (-2%)
- 535๋ฑ (Top 15%)
Score : 0.41850 Rank : 428 (Top 13.19%)
๋ฐฉ๋ฒ2 - sklearn์ TimeSeriesSplit๊ณผ GridSearchCV๋ฅผ ์ด์ฉํ์ฌ ํ๋์ class๋ก ์ ์ํ๋ค.
class TimeSeries_GridCV_Model:
def __init__(self, n_splits=5):
self.n_splits = n_splits
self.tscv = TimeSeriesSplit(n_splits=n_splits)
def fit_and_evaluate(self, model, params, scorer, X, y):
for train_index, test_index in self.tscv.split(dataTrain):
X_train, X_test = X.iloc[train_index], X.iloc[test_index]
y_train, y_test = y.iloc[train_index], y.iloc[test_index]
grid_search = GridSearchCV(model, params, scoring = scorer, cv=5, error_score='raise')
grid_search.fit(X_train.values, np.log1p(y_train))
y_pred = grid_search.predict(X_test.values)
error = rmsle(np.exp(np.log1p(y_test)), np.exp(y_pred), False)
print(grid_search.best_params_)
print("RMSLE Value:", error)
return grid_search
def plot_parameters(self, grid_search):
fig, ax = plt.subplots()
fig.set_size_inches(12, 5)
df = pd.DataFrame(grid_search_result.cv_results_)
df["alpha"] = df["param_alpha"]
df["rmsle"] = -df["mean_test_score"]
sns.pointplot(data=df, x='alpha', y='rmsle', ax=ax)
def predict(self, grid_search, dataTest):
predsTest = grid_search.predict(X = dataTest)
return predsTest
- Ridge : 1.04990
-
Lasso : 1.04370
- windspeed์ humidity 0๊ฐ์ ์ค์ 0๊ฐ์ด ์๋ null๊ฐ์ด 0์ผ๋ก ํ์๋ ๊ฑฐ์๋ค โ
RandomForestClassifier
๋ฅผ ์ด์ฉํด null๊ฐ ์ฑ์
์ ์ฉํ๋ Techinque
pd.DatetimeIndex
- dataset์
datetime
feature์์hour
,day
,month
,year
์ ๋ณด๋ฅผ ์ถ์ถํ๋ค.
Detect special missing value like 0
- null ๊ฐ์ด ์์ด๋ณด์์ง๋ง,
windspeed
,humidity
feature์์ ๋ฐ๊ฒฌ๋๋ 0 ๊ฐ์ ์ค์ ์ธ๊ณ์์๋ ์กด์ฌํ ์ ์๋ ๋ฐ์ดํฐ์ด๊ธฐ์ missing value์์ ์์๋ผ ์ ์๋ค.
Fill missing value with RandomForestClassifier
- missing value๊ฐ ์๋ feature๋ฅผ missing value๊ฐ ์๋ feature๋ค์ ์ด์ฉํ์ฌ RandomForestClassifier๋ฅผ ํ์ต์์ผ ๊ฐ์ ์ฑ์ธ ์ ์๋ค.
- ๊ธฐ์กด ํต๊ณ๊ฐ๋ค๋ก๋ง ์ฑ์ฐ๋ ๋ณด๋ค ์๋ฏธ์๋ ๊ฐ์ ์ฑ์ธ ์ ์๋ค.
metrics.make_scorer
metrics.make_scorer
์ ์ด์ฉํ์ฌ ๋ด๊ฐ ์ง์ ์ ์ํ ์ค์ฐจ ํจ์๋ฅผGridSearCV
์ scorer๋ก ์ฌ์ฉํ ์ ์๋ค.
Check distribution
- trian ๋ฐ์ดํฐ์ label๊ฐ๋ค์ ๋ถํฌ์, model์ predict ๊ฐ๋ค์ ๋ถํฌ๋ฅผ ์๊ฐํ ํ ๋น๊ตํด์ ํ์ต ์ ๋๋ฅผ ํ์ ํด๋ณผ ์ ์๋ค.
Leave a comment