|
32 | 32 | .. |make_column_transformer| replace::
|
33 | 33 | :class:`~sklearn.compose.make_column_transformer`
|
34 | 34 |
|
35 |
| -.. |HGBR| replace:: |
36 |
| - :class:`~sklearn.ensemble.HistGradientBoostingRegressor` |
| 35 | +.. |RidgeCV| replace:: |
| 36 | + :class:`~sklearn.linear_model.RidgeCV` |
37 | 37 |
|
38 | 38 | .. |ToDatetime| replace::
|
39 | 39 | :class:`~skrub.ToDatetime`
|
|
128 | 128 | # |DatetimeEncoder| is used on the correct column(s).
|
129 | 129 | pprint(table_vec_weekday.transformers_)
|
130 | 130 |
|
| 131 | +############################################################################### |
| 132 | +# The |DatetimeEncoder| can generate additional periodic features using either |
| 133 | +# B-Splines (|SplineTransformer|) or trigonometric functions. To do so, set the |
| 134 | +# ``periodic encoding`` parameter ``circular`` or ``spline``. In this |
| 135 | +# example, we use ``spline``. |
| 136 | + |
| 137 | +table_vec_periodic = TableVectorizer( |
| 138 | + datetime=DatetimeEncoder( |
| 139 | + periodic_encoding="spline", |
| 140 | + ) |
| 141 | +).fit(X) |
| 142 | + |
131 | 143 | ###############################################################################
|
132 | 144 | # Prediction with datetime features
|
133 | 145 | # ---------------------------------
|
134 | 146 | #
|
135 | 147 | # For prediction tasks, we recommend using the |TableVectorizer| inside a
|
136 | 148 | # pipeline, combined with a model that can use the features extracted by the
|
137 | 149 | # |DatetimeEncoder|.
|
138 |
| -# Here we'll use a |HGBR| as our learner. |
| 150 | +# Here we'll use a |RidgeCV| model as our learner. |
139 | 151 | #
|
140 |
| -from sklearn.ensemble import HistGradientBoostingRegressor |
| 152 | +from sklearn.impute import SimpleImputer |
| 153 | +from sklearn.linear_model import RidgeCV |
141 | 154 | from sklearn.pipeline import make_pipeline
|
| 155 | +from sklearn.preprocessing import StandardScaler |
142 | 156 |
|
143 |
| -pipeline = make_pipeline(table_vec, HistGradientBoostingRegressor()) |
144 |
| -pipeline_weekday = make_pipeline(table_vec_weekday, HistGradientBoostingRegressor()) |
| 157 | +pipeline = make_pipeline(table_vec, StandardScaler(), SimpleImputer(), RidgeCV()) |
| 158 | +pipeline_weekday = make_pipeline( |
| 159 | + table_vec_weekday, StandardScaler(), SimpleImputer(), RidgeCV() |
| 160 | +) |
| 161 | +pipeline_periodic = make_pipeline( |
| 162 | + table_vec_periodic, StandardScaler(), SimpleImputer(), RidgeCV() |
| 163 | +) |
145 | 164 |
|
146 | 165 | ###############################################################################
|
147 | 166 | # Evaluating the model
|
|
0 commit comments