離婚後の日記

離婚した。

4.6 専門家知識の利用

(60m)16:30~17:30

4.6

自転車レンタルを例に総合。

ランダムフォレストでの推測

時間要素を追加

[0],[3],[6],...

#[0時],[3時]...

曜日要素を追加

X_hour_week=np.hstack([citibike.index.dayofweek.values.reshape(-1,1),citibike.index.hour.values.reshape(-1,1)])

[ 5, 0],
[ 5, 3],
[ 5, 6],
[ 5, 9],...

#[土曜,0時],[土曜,3時]...

線形モデルで解析

線形で解釈できない部分をワンホットエンコーダーで変換

enc=OneHotEncoder()
X_hour_week_onehot=enc.fit_transform(X_hour_week).toarray()

[ 0., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0., 0., 0.,
0., 0.],
[ 0., 0., 0., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0.,
0., 0.],
[ 0., 0., 0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0.,
0., 0.],...

#各項目をダミー[月,火,水,木,金,土,日,0,3,6,9,12,15,18,21]

 

交互作用特徴量で曜日かける時刻を作成

from sklearn.preprocessing import PolynomialFeatures
poly_transformer=PolynomialFeatures(degree=2,interaction_only=True,include_bias=False)
X_hour_week_onehot_poly=poly_transformer.fit_transform(X_hour_week_onehot)

Ridge

線形とランダムフォレストが同等に。

 

ここできちんと復習しよう。

いろいろと打ち込んでいるだけなので。