Skip to content

Commit 0a414c7

Browse files
author
Gsaes
committed
Modif benchmark
1 parent 625701e commit 0a414c7

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

examples/benchmark.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,11 @@ plt.show()
321321
In this section, we present an MLP model of data imputation using Keras, which can be installed using a "pip install tensorflow".
322322

323323
```python
324-
from qolmat.imputations import imputers_keras
325-
import tensorflow as tf
324+
from qolmat.imputations import imputers_pytorch
325+
try:
326+
import torch.nn as nn
327+
except ModuleNotFoundError:
328+
raise PyTorchExtraNotInstalled
326329
```
327330

328331
For the MLP model, we work on a dataset that corresponds to weather data with missing values. We add missing MCAR values on the features "TEMP", "PRES" and other features with NaN values. The goal is impute the missing values for the features "TEMP" and "PRES" by a Deep Learning method. We add features to take into account the seasonality of the data set and a feature for the station name
@@ -340,13 +343,17 @@ For the example, we use a simple MLP model with 3 layers of neurons.
340343
Then we train the model without taking a group on the stations
341344

342345
```python
343-
estimator = tf.keras.models.Sequential([
344-
tf.keras.layers.Dense(256, activation='relu'),
345-
tf.keras.layers.Dense(128, activation='relu'),
346-
tf.keras.layers.Dense(64, activation='relu'),
347-
tf.keras.layers.Dense(1)])
348-
estimator.compile(optimizer='adam', loss='mae')
349-
dict_imputers["MLP"] = imputer_mlp = imputers_keras.ImputerRegressorKeras(estimator=estimator, groups=['station'], handler_nan = "column")
346+
estimator = nn.Sequential(
347+
nn.Linear(np.sum(df_data.isna().sum()==0), 256),
348+
nn.ReLU(),
349+
nn.Linear(256, 128),
350+
nn.ReLU(),
351+
nn.Linear(128, 64),
352+
nn.ReLU(),
353+
nn.Linear(64, 1)
354+
)
355+
# imputers_pytorch.build_mlp_example(input_dim=np.sum(df_data.isna().sum()==0), list_num_neurons=[256,128,64])
356+
dict_imputers["MLP"] = imputer_mlp = imputers_pytorch.ImputerRegressorPyTorch(estimator=estimator, groups=['station'], handler_nan = "column", epochs=500)
350357
```
351358

352359
We can re-run the imputation model benchmark as before.

0 commit comments

Comments
 (0)