You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-4Lines changed: 26 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -162,11 +162,28 @@ model.fit(
162
162
163
163
164
164
### Implement your own model:
165
-
mambular allows users to easily integrate their custom models into the existing logic. Simply create a pytorch model and define its forward pass. Instead of inheriting from nn.Module, inherit from mambulars BaseModel. Each mambular model takse three arguments. The number of classes, e.g. = 1 for regression or = 2 for binary classification. For distributional regression, while this argument must be provided, it is determined automatically depending on the chosen distribution. Additionally, it takes two arguments directly passed from preprocessor. The cat_feature_info and num_feature_info for categorical and numerical feature information of e.g. the provided shape. Additionally, you can provide a config argument, which you can either use simialr to the implemented models, or leave empty as shown below. A custom model could hence look just like this:
165
+
mambular allows users to easily integrate their custom models into the existing logic. Simply create a pytorch model and define its forward pass. Instead of inheriting from nn.Module, inherit from mambulars BaseModel. Each mambular model takse three arguments. The number of classes, e.g. = 1 for regression or = 2 for binary classification. For distributional regression, while this argument must be provided, it is determined automatically depending on the chosen distribution. Additionally, it takes two arguments directly passed from preprocessor. The cat_feature_info and num_feature_info for categorical and numerical feature information of e.g. the provided shape. Additionally, you can provide a config argument, which you can either implement similarly to the implemented configs, or simply use one of the Default Configs provided. A custom model could hence look just like this:
166
166
167
167
168
+
1. First, define your config
169
+
170
+
```python
171
+
from dataclasses import dataclass
172
+
173
+
@dataclass
174
+
classMyConfig:
175
+
lr: float=1e-04
176
+
lr_patience: int=10
177
+
weight_decay: float=1e-06
178
+
lr_factor: float=0.1
179
+
```
180
+
181
+
2. Second, define your model just as you would for a nn.Module. Simply define the architecture and the forward pass
182
+
168
183
```python
169
184
from mambular.base_models import BaseModel
185
+
import torch
186
+
import torch.nn
170
187
171
188
classMyCustomModel(BaseModel):
172
189
def__init__(
@@ -197,19 +214,24 @@ class MyCustomModel(BaseModel):
197
214
return output
198
215
```
199
216
200
-
To leverage the mambular API, you can build a regression, classification or distributional regression model that can leverage all of mambulars built-in methods, by using the following:
217
+
3.To leverage the mambular API, you can build a regression, classification or distributional regression model that can leverage all of mambulars built-in methods, by using the following:
Subsequently, you can fit, evaluate and predict with your model just like with any other mambualr model.
227
+
4.Subsequently, you can fit, evaluate and predict with your model just like with any other mambualr model.
211
228
To achieve the same for classification or disrtibutional regression, instead of inheriting from the SklearnbaseRegressor, simply inherit from the SklearnBaseClassifier and SklearnBaseLSS.
0 commit comments