Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/sklearn14 #163

Merged
merged 7 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions docs/end_to_end.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ preproc_pipe = make_union(gpp, fncv3_selector)
xgb = XGBRegressor()
cve = CrossValEstimator(estimator=xgb, cv=TimeSeriesSplit(n_splits=5))
ens = NumeraiEnsemble()
ens.set_transform_request(era_series=True)
fn = FeatureNeutralizer(proportion=0.5)
fn.set_predict_request(era_series=True, features=True)
full_pipe = make_meta_pipeline(preproc_pipe, cve, ens, fn)

# Train full model
full_pipe.fit(X, y, numeraiensemble__eras=eras);
full_pipe.fit(X, y, era_series=era_series);

# Inference on validation data
val_preds = full_pipe.predict(val_X, eras=val_eras, features=val_features)
val_preds = full_pipe.predict(val_X, era_series=val_eras, features=val_features)
```

## 2. Multi Classification Ensemble
Expand All @@ -85,12 +87,14 @@ model = DecisionTreeClassifier()
crossval1 = CrossValEstimator(estimator=model, cv=TimeSeriesSplit(n_splits=3), predict_func='predict_proba')
pred_rud = PredictionReducer(n_models=3, n_classes=5)
ens2 = NumeraiEnsemble(donate_weighted=True)
ens2.set_transform_request(era_series=True)
neut2 = FeatureNeutralizer(proportion=0.5)
neut2.set_predict_request(era_series=True, features=True)
full_pipe = make_meta_pipeline(preproc_pipe, crossval1, pred_rud, ens2, neut2)

full_pipe.fit(X, y, numeraiensemble__eras=eras)
full_pipe.fit(X, y, era_series=era_series)

preds = full_pipe.predict(val_X, eras=val_eras, features=val_features)
preds = full_pipe.predict(val_X, era_series=val_eras, features=val_features)
```

## 3. Ensemble of ensemble of regressors
Expand All @@ -107,6 +111,7 @@ from numerblox.meta import CrossValEstimator, make_meta_pipeline
from numerblox.ensemble import NumeraiEnsemble,
from numerblox.neutralizers import FeatureNeutralizer


pipes = []
for i in range(3):
model = DecisionTreeRegressor()
Expand All @@ -116,12 +121,12 @@ for i in range(3):

models = make_column_transformer(*[(pipe, features.columns.tolist()) for pipe in pipes])
ens_end = NumeraiEnsemble()
ens_end.set_transform_request(era_series=True)
neut = FeatureNeutralizer(proportion=0.5)
neut.set_predict_request(era_series=True, features=True)
full_pipe = make_meta_pipeline(models, ens_end, neut)

full_pipe.fit(X, y,
columntransformer__eras=eras,
numeraiensemble__eras=eras)
full_pipe.fit(X, y, era_series=era_series)

preds = full_pipe.predict(val_X, eras=val_eras, features=val_features)
preds = full_pipe.predict(val_X, era_series=val_eras, features=val_features)
```
2 changes: 1 addition & 1 deletion docs/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Make sure to include the era column as a `pd.Series` in the `fit` method.
from numerblox.models import EraBoostedXGBRegressor

model = EraBoostedXGBRegressor(proportion=0.5, trees_per_step=10, num_iters=20)
model.fit(X=X_train, y=y_train, eras=eras_train)
model.fit(X=X_train, y=y_train, era_series=eras_train)

predictions = model.predict(X_live)
```
3 changes: 3 additions & 0 deletions docs/postprocessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ feature_data = pd.DataFrame([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]])
era_data = pd.Series([1, 1, 2])

neutralizer = FeatureNeutralizer(pred_name="prediction", proportion=0.5)
neutralizer.set_predict_request(era_series=True, features=True)
neutralizer.fit()
neutralized_predictions = neutralizer.predict(X=predictions, features=feature_data, eras=era_data)
```
Expand All @@ -40,6 +41,7 @@ feature_data = pd.DataFrame([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]])
era_data = pd.Series([1, 1, 2])

neutralizer = FeatureNeutralizer(pred_name=["prediction1", "prediction2"], proportion=[0.5, 0.7])
neutralizer.set_predict_request(era_series=True, features=True)
neutralizer.fit()
neutralized_predictions = neutralizer.predict(X=predictions, features=feature_data, eras=era_data)
```
Expand All @@ -64,6 +66,7 @@ feature_data = pd.DataFrame([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]])
era_data = pd.Series([1, 1, 2])

penalizer = FeaturePenalizer(max_exposure=0.1, pred_name="prediction")
penalizer.set_predict_request(era_series=True, features=True)
penalizer.fit(X=predictions)
penalized_predictions = penalizer.predict(X=predictions, features=feature_data, eras=era_data)
```
15 changes: 9 additions & 6 deletions docs/preprocessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ enhanced_data = feature_gen.fit_transform(dataf)

`EraQuantileProcessor` transforms features into quantiles by era. This can help normalize data and make patterns more distinguishable. Quantiling operation are parallelized across features for faster processing.

Using `.transform` requires passing the era column as a `pd.Series`. This is because the quantiles are calculated per era so it needs that information along with the raw input features.
Using `.transform` requires passing `era_series`. This is because the quantiles are calculated per era so it needs that information along with the raw input features.

```py
from numerblox.preprocessing import EraQuantileProcessor

eq_processor = EraQuantileProcessor(num_quantiles=50, random_state=42)
transformed_data = eq_processor.fit_transform(X, eras=eras_series)
eq_processor.set_transform_request(era_series=True)
transformed_data = eq_processor.fit_transform(X, era_series=eras_series)
```

### TickerMapper
Expand All @@ -79,14 +80,15 @@ mapped_data = ticker_mapper.transform(dataf["ticker"])

`LagPreProcessor` generates lag features based on specified windows. Lag features can capture temporal patterns in time-series data.

Note that `LagPreProcessor` needs a series of `tickers` in the `.transform` step.
Note that `LagPreProcessor` needs a `ticker_series` in the `.transform` step.

```py
from numerblox.preprocessing import LagPreProcessor

lag_processor = LagPreProcessor(windows=[5, 10, 20])
lag_processor.set_transform_request(ticker_series=True)
lag_processor.fit(X)
lagged_data = lag_processor.transform(X, tickers=tickers_series)
lagged_data = lag_processor.transform(X, ticker_series=tickers_series)

```

Expand All @@ -96,18 +98,19 @@ lagged_data = lag_processor.transform(X, tickers=tickers_series)

WARNING: `DifferencePreProcessor` works only on `pd.DataFrame` and with columns that are generated in `LagPreProcessor`. If you are using these in a Pipeline make sure `LagPreProcessor` is defined before `DifferencePreProcessor` and that output API is set to Pandas (`pipeline.set_output(transform="pandas")`).

Note that `LagPreProcessor` needs a series of `tickers` in the `.transform` step so a pipeline with both preprocessors will need a `tickers` argument in `.transform`.
Note that `LagPreProcessor` needs a `ticker_series` in the `.transform` step so a pipeline with both preprocessors will need a `tickers` argument in `.transform`.

```py
from sklearn.pipeline import make_pipeline
from numerblox.preprocessing import DifferencePreProcessor

lag = LagPreProcessor(windows=[5, 10])
lag.set_transform_request(ticker_series=True)
diff = DifferencePreProcessor(windows=[5, 10], pct_diff=True)
pipe = make_pipeline(lag, diff)
pipe.set_output(transform="pandas")
pipe.fit(X)
diff_data = pipe.transform(X, tickers=tickers_series)
diff_data = pipe.transform(X, ticker_series=tickers_series)
```

### PandasTaFeatureGenerator
Expand Down
Loading
Loading