Utility function to build a Keras MLP.
(integer(1))
Number of input features.
(integer(1))
Number of targets.
(numeric())
Hidden nodes in network, each element in vector represents number
of hidden nodes in respective layer.
(list())
Arguments passed to keras::layer_dense.
(character(1))
Activation function passed to keras::layer_activation.
Default is linear.
(list())
Parameters for activation function, see
keras::layer_activation.
(numeric(1))
Optional dropout layer, if NULL
then no dropout layer added
otherwise either same dropout will be added to all layers.
(logical(1))
If TRUE
(default) then batch normalisation is applied
to all layers.
(list())
Parameters for batch normalisation, see
keras::layer_batch_normalization.
This function is a helper for R users with less Python experience. Currently it is limited to simple MLPs and with identical layers. More advanced networks will require manual creation with keras.
# \donttest{
if (requireNamespaces("keras")) {
build_keras_net(4L, 2L)
build_keras_net(n_in = 4L, n_out = 2L, nodes = c(32L, 64L, 32L),
activation = "elu", dropout = 0.4)
}
#> Error: Valid installation of TensorFlow not found.
#>
#> Python environments searched for 'tensorflow' package:
#> /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12
#> /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12
#>
#> Python exception encountered:
#> Traceback (most recent call last):
#> File "/Users/runner/work/_temp/Library/reticulate/python/rpytools/loader.py", line 119, in _find_and_load_hook
#> return _run_hook(name, _hook)
#> ^^^^^^^^^^^^^^^^^^^^^^
#> File "/Users/runner/work/_temp/Library/reticulate/python/rpytools/loader.py", line 93, in _run_hook
#> module = hook()
#> ^^^^^^
#> File "/Users/runner/work/_temp/Library/reticulate/python/rpytools/loader.py", line 117, in _hook
#> return _find_and_load(name, import_)
#> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#> ModuleNotFoundError: No module named 'tensorflow'
#>
#>
#> You can install TensorFlow using the install_tensorflow() function.
# }