Learn R Programming

utiml: Utilities for Multi-label Learning

The utiml package is a framework to support multi-label processing, like Mulan on Weka.

The main methods available on this package are organized in the groups:

  • Classification methods
  • Evaluation methods
  • Pre-process utilities
  • Sampling methods
  • Threshold methods

Instalation

The installation process is similar to other packages available on CRAN:

install.packages("utiml")

This will also install mldr. To run the examples in this document, you also need to install the packages:

# Base classifiers (SVM and Random Forest)
install.packages(c("e1071", "randomForest"))

Install via github (development version)

devtools::install_github("rivolli/utiml")

Multi-label Classification

Running Binary Relevance Method

library(utiml)

# Create two partitions (train and test) of toyml multi-label dataset
ds <- create_holdout_partition(toyml, c(train=0.65, test=0.35))

# Create a Binary Relevance Model using e1071::svm method
brmodel <- br(ds$train, "SVM", seed=123)

# Predict
prediction <- predict(brmodel, ds$test)

# Show the predictions
head(as.bipartition(prediction))
head(as.ranking(prediction))

# Apply a threshold
newpred <- rcut_threshold(prediction, 2)

# Evaluate the models
result <- multilabel_evaluate(ds$tes, prediction, "bipartition")
thresres <- multilabel_evaluate(ds$tes, newpred, "bipartition")

# Print the result
print(round(cbind(Default=result, RCUT=thresres), 3))

Running Ensemble of Classifier Chains

library(utiml)

# Create three partitions (train, val, test) of emotions dataset
partitions <- c(train = 0.6, val = 0.2, test = 0.2)
ds <- create_holdout_partition(emotions, partitions, method="iterative")

# Create an Ensemble of Classifier Chains using Random Forest (randomForest package)
eccmodel <- ecc(ds$train, "RF", m=3, cores=parallel::detectCores(), seed=123)

# Predict
val <- predict(eccmodel, ds$val, cores=parallel::detectCores())
test <- predict(eccmodel, ds$test, cores=parallel::detectCores())

# Apply a threshold
thresholds <- scut_threshold(val, ds$val, cores=parallel::detectCores())
new.val <- fixed_threshold(val, thresholds)
new.test <- fixed_threshold(test, thresholds)

# Evaluate the models
measures <- c("subset-accuracy", "F1", "hamming-loss", "macro-based") 

result <- cbind(
  Test = multilabel_evaluate(ds$tes, test, measures),
  TestWithThreshold = multilabel_evaluate(ds$tes, new.test, measures),
  Validation = multilabel_evaluate(ds$val, val, measures),
  ValidationWithThreshold = multilabel_evaluate(ds$val, new.val, measures)
)

print(round(result, 3))

More examples and details are available on functions documentations and vignettes, please refer to the documentation.

How to cite?

@article{RJ-2018-041,
  author = {Adriano Rivolli and Andre C. P. L. F. de Carvalho},
  title = {{The utiml Package: Multi-label Classification in R}},
  year = {2018},
  journal = {{The R Journal}},
  doi = {10.32614/RJ-2018-041},
  url = {https://doi.org/10.32614/RJ-2018-041},
  pages = {24--37},
  volume = {10},
  number = {2}
}

Copy Link

Version

Install

install.packages('utiml')

Monthly Downloads

193

Version

0.1.7

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Adriano Rivolli

Last Published

May 31st, 2021

Functions in utiml (0.1.7)

as.matrix.mlconfmat

Convert a multi-label Confusion Matrix to matrix
as.mlresult

Convert a matrix prediction in a multi label prediction
as.ranking

Convert a mlresult to a ranking matrix
cc

Classifier Chains for multi-label Classification
baseline

Baseline reference for multilabel classification
as.matrix.mlresult

Convert a mlresult to matrix
as.bipartition

Convert a mlresult to a bipartition matrix
as.probability

Convert a mlresult to a probability matrix
brplus

BR+ or BRplus for multi-label Classification
br

Binary Relevance for multi-label Classification
create_random_subset

Create a random subset of a dataset
compute_multilabel_predictions

Compute the multi-label ensemble predictions based on some vote schema
clr

Calibrated Label Ranking (CLR) for multi-label Classification
create_subset

Create a subset of a dataset
dbr

Dependent Binary Relevance (DBR) for multi-label Classification
homer

Hierarchy Of Multilabel classifiER (HOMER)
fixed_threshold

Apply a fixed threshold in the results
cv

Multi-label cross-validation
fill_sparse_mldata

Fill sparse dataset with 0 or '' values
foodtruck

Foodtruck multi-label dataset.
is.bipartition

Test if a mlresult contains crisp values as default
ebr

Ensemble of Binary Relevance for multi-label Classification
ecc

Ensemble of Classifier Chains for multi-label Classification
is.probability

Test if a mlresult contains score values as default
mcut_threshold

Maximum Cut Thresholding (MCut)
mlknn

Multi-label KNN (ML-KNN) for multi-label Classification
mldata

Fix the mldr dataset to use factors
multilabel_confusion_matrix

Compute the confusion matrix for a multi-label prediction
multilabel_evaluate

Evaluate multi-label predictions
normalize_mldata

Normalize numerical attributes
merge_mlconfmat

Join a list of multi-label confusion matrix
ns

Nested Stacking for multi-label Classification
mbr

Meta-BR or 2BR for multi-label Classification
lp

Label Powerset for multi-label Classification
partition_fold

Create the multi-label dataset from folds
predict.CLRmodel

Predict Method for CLR
pcut_threshold

Proportional Thresholding (PCut)
predict.DBRmodel

Predict Method for DBR
mltrain

Build transformation models
lift

LIFT for multi-label Classification
lcard_threshold

Threshold based on cardinality
mlpredict

Prediction transformation problems
multilabel_measures

Return the name of all measures
predict.BASELINEmodel

Predict Method for BASELINE
multilabel_prediction

Create a mlresult object
predict.HOMERmodel

Predict Method for HOMER
predict.BRmodel

Predict Method for Binary Relevance
print.BRPmodel

Print BRP model
predict.BRPmodel

Predict Method for BR+ (brplus)
predict.CCmodel

Predict Method for Classifier Chains
print.BRmodel

Print BR model
print.PPTmodel

Print PPT model
print.ESLmodel

Print ESL model
print.LIFTmodel

Print LIFT model
predict.PSmodel

Predict Method for Pruned Set Transformation
predict.PPTmodel

Predict Method for Pruned Problem Transformation
predict.LIFTmodel

Predict Method for LIFT
create_kfold_partition

Create the k-folds partition based on the specified algorithm
create_holdout_partition

Create a holdout partition based on the specified algorithm
eps

Ensemble of Pruned Set for multi-label Classification
predict.LPmodel

Predict Method for Label Powerset
predict.EPSmodel

Predict Method for Ensemble of Pruned Set Transformation
+.mlconfmat

Join two multi-label confusion matrix
esl

Ensemble of Single Label
predict.ESLmodel

Predict Method for Ensemble of Single Label
ppt

Pruned Problem Transformation for multi-label Classification
predict.PruDentmodel

Predict Method for PruDent
print.PSmodel

Print PS model
print.MLKNNmodel

Print MLKNN model
predict.MBRmodel

Predict Method for Meta-BR/2BR
ps

Pruned Set for multi-label Classification
predict.RAkELmodel

Predict Method for RAkEL
print.mlconfmat

Print a Multi-label Confusion Matrix
print.NSmodel

Print NS model
predict.EBRmodel

Predict Method for Ensemble of Binary Relevance
predict.ECCmodel

Predict Method for Ensemble of Classifier Chains
predict.MLKNNmodel

Predict Method for ML-KNN
[.mlresult

Filter a Multi-Label Result
print.mlresult

Print the mlresult
subset_correction

Subset Correction of a predicted result
predict.NSmodel

Predict Method for Nested Stacking
print.CCmodel

Print CC model
print.PruDentmodel

Print PruDent model
print.CLRmodel

Print CLR model
predict.RDBRmodel

Predict Method for RDBR
rakel

Random k-labelsets for multilabel classification
print.ECCmodel

Print ECC model
print.EPSmodel

Print EPS model
predict.RPCmodel

Predict Method for RPC
print.EBRmodel

Print EBR model
print.DBRmodel

Print DBR model
print.RDBRmodel

Print RDBR model
remove_skewness_labels

Remove unusual or very common labels
print.RAkELmodel

Print RAkEL model
remove_unique_attributes

Remove unique attributes
print.randomModel

Print Random model
prudent

PruDent classifier for multi-label Classification
print.RPCmodel

Print RPC model
remove_attributes

Remove attributes from the dataset
print.kFoldPartition

Print a kFoldPartition object
rpc

Ranking by Pairwise Comparison (RPC) for multi-label Classification
print.majorityModel

Print Majority model
scut_threshold

SCut Score-based method
toyml

Toy multi-label dataset.
summary.mltransformation

Summary method for mltransformation
remove_labels

Remove labels from the dataset
print.MBRmodel

Print MBR model
print.LPmodel

Print LP model
rdbr

Recursive Dependent Binary Relevance (RDBR) for multi-label Classification
remove_unlabeled_instances

Remove examples without labels
rcut_threshold

Rank Cut (RCut) threshold method
utiml

utiml: Utilities for Multi-Label Learning
replace_nominal_attributes

Replace nominal attributes Replace the nominal attributes by binary attributes.
utiml_measure_names

Return the name of measures