MyNixOS website logo
Description

Fast Compact Multilayer Perceptrons.

A small multilayer perceptron implementation for 'R'. It supports regression and classification, multiple hidden layers, mini-batch training, Adam, SGD, momentum, Nesterov, RPROP, GRPROP and L-BFGS optimizers, dropout, L2 regularization, early stopping, convergence thresholds, gradient clipping, sample and class weights, callback hooks, target scaling and robust Huber loss for regression, 'Rcpp' forward-pass kernels, formula interfaces, model evaluation with balanced classification metrics, cross-validation, compact tuning, permutation importance, model persistence helpers, and 'S3' prediction methods. Methods follow Rumelhart, Hinton and Williams (1986) <doi:10.1038/323533a0>, with optimizers including Riedmiller and Braun (1993) <doi:10.1109/ICNN.1993.298623>, Nocedal (1980) <doi:10.1090/S0025-5718-1980-0572855-7>, and Kingma and Ba (2014) <doi:10.48550/arXiv.1412.6980>.

neuralnetwork

neuralnetwork fits compact multilayer perceptrons for everyday R workflows: formula input, tabular data, regression, classification, tuning, cross validation, and readable model objects. It is designed for problems where nnet feels too small, neuralnet feels too manual, and a full deep-learning framework would be more machinery than the job needs.

Install

install.packages("neuralnetwork")

To install the local source tarball:

install.packages("neuralnetwork_0.1.0.tar.gz", repos = NULL, type = "source")

Quick Start

library(neuralnetwork)

fit <- nn_fit(
  Species ~ .,
  data = iris,
  hidden = "auto",
  optimizer = "auto",
  epochs = 20,
  validation_split = 0.2,
  seed = 1,
  verbose = FALSE
)

fit
predict(fit, iris[1:5, ], type = "class")
round(predict(fit, iris[1:5, ], type = "prob"), 3)

ev <- nn_evaluate(fit, iris)
ev

The printed model gives the architecture, optimizer, loss, backend, training length, final training score, and validation score when available. The evaluation object prints metrics as a small table and includes the confusion matrix for classification.

Regression

Regression uses the same interface. Targets can be scaled during training and returned on the original scale for prediction.

fit_reg <- nn_fit(
  mpg ~ wt + hp + disp,
  data = mtcars,
  hidden = c(8, 4),
  optimizer = "adam",
  epochs = 40,
  batch_size = 8,
  learning_rate = 0.01,
  validation_split = 0.2,
  seed = 2,
  verbose = FALSE
)

predict(fit_reg, mtcars[1:5, ])
nn_evaluate(fit_reg, mtcars)

For regression problems with outliers, use Huber loss:

fit_huber <- nn_fit(
  mpg ~ wt + hp + disp,
  data = mtcars,
  hidden = c(8, 4),
  optimizer = "adam",
  loss = "huber",
  huber_delta = 1,
  epochs = 40,
  batch_size = 8,
  learning_rate = 0.01,
  seed = 3,
  verbose = FALSE
)

Choosing Settings

Good first defaults:

  • hidden = "auto" for a compact task-aware architecture.
  • optimizer = "auto" for L-BFGS on small deterministic problems and Adam when using stochastic features such as dropout or callbacks.
  • validation_split = 0.2 when you want validation loss, early stopping, or validation-based tuning.
  • metric = "balanced_accuracy" for imbalanced classification, metric = "f1" when the positive class matters, and metric = "mae" or metric = "rmse" for regression.
  • loss = "huber" for regression data where outliers may dominate squared error.

Tuning and Validation

tuned <- nn_tune(
  Species ~ .,
  data = iris,
  grid = list(
    hidden = list(4, c(6, 3)),
    learning_rate = c(0.01, 0.003)
  ),
  metric = "balanced_accuracy",
  epochs = 8,
  validation_split = 0.2,
  seed = 4,
  verbose = FALSE
)

tuned
tuned$best_model
cv <- nn_cv(
  Species ~ .,
  data = iris,
  k = 3,
  metric = "f1",
  hidden = 4,
  epochs = 5,
  seed = 5,
  verbose = FALSE
)

cv

Feature Importance

imp <- nn_permutation_importance(
  fit_reg,
  mtcars,
  metric = "mae",
  n_repeats = 3,
  seed = 6
)

imp

Function Map

NeedUse
Fit a modelnn_fit()
Predict classes, probabilities, or numeric responsespredict()
Evaluate metricsnn_evaluate()
Tune a gridnn_tune()
Cross-validatenn_cv()
Estimate feature importancenn_permutation_importance()
Save and loadnn_save(), nn_load()
Use nnet / neuralnet style helpersnn_multinom(), nn_compute(), nn_generalized_weights()

What Is Included

  • Formula, data frame, matrix, and vector inputs.
  • Regression, binary classification, and multiclass classification.
  • Multiple hidden layers, including hidden = 0 for no hidden layer.
  • Adam, SGD, momentum, Nesterov, RPROP, GRPROP, and L-BFGS optimizers.
  • Automatic hidden-layer sizing, activation choice, and optimizer choice.
  • Portable Rcpp forward-pass kernels when available.
  • Dropout, L2 regularization, gradient clipping, learning-rate decay, validation splits, early stopping, and callbacks.
  • Sample weights and balanced class weights.
  • Huber loss for robust regression.
  • Accuracy, balanced accuracy, macro F1, log loss, RMSE, MAE, and R-squared.
  • Tuning, repeated k-fold cross-validation, permutation importance, save/load helpers, and S3 predict(), print(), plot(), summary(), and coef().
  • Compatibility helpers for common nnet and neuralnet workflows: nn_multinom(), nn_class_ind(), nn_which_is_max(), nn_compute(), nn_generalized_weights(), nn_gwplot(), nn_hessian(), and nn_confint().

See vignette("neuralnetwork") for a fuller walkthrough.

For reference-style help inside R, see ?neuralnetwork, ?neuralnetwork-metrics, ?neuralnetwork-callbacks, and ?neuralnetwork-objects.

Metadata

Version

0.1.0

License

Unknown

Platforms (79)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    wasip1
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasip1
  • wasm64-wasip1
  • x86_64-cygwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows