# DAL ToolBox
# version 1.1.727
source("https://raw.githubusercontent.com/cefet-rj-dal/daltoolbox/main/jupyter.R")
#loading DAL
load_library("daltoolbox")
Loading required package: daltoolbox Registered S3 method overwritten by 'quantmod': method from as.zoo.data.frame zoo Attaching package: ‘daltoolbox’ The following object is masked from ‘package:base’: transform
iris <- datasets::iris
head(iris)
Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species | |
---|---|---|---|---|---|
<dbl> | <dbl> | <dbl> | <dbl> | <fct> | |
1 | 5.1 | 3.5 | 1.4 | 0.2 | setosa |
2 | 4.9 | 3.0 | 1.4 | 0.2 | setosa |
3 | 4.7 | 3.2 | 1.3 | 0.2 | setosa |
4 | 4.6 | 3.1 | 1.5 | 0.2 | setosa |
5 | 5.0 | 3.6 | 1.4 | 0.2 | setosa |
6 | 5.4 | 3.9 | 1.7 | 0.4 | setosa |
#extracting the levels for the dataset
slevels <- levels(iris$Species)
slevels
# preparing dataset for random sampling
set.seed(1)
sr <- sample_random()
sr <- train_test(sr, iris)
iris_train <- sr$train
iris_test <- sr$test
tbl <- rbind(table(iris[,"Species"]),
table(iris_train[,"Species"]),
table(iris_test[,"Species"]))
rownames(tbl) <- c("dataset", "training", "test")
head(tbl)
setosa | versicolor | virginica | |
---|---|---|---|
dataset | 50 | 50 | 50 |
training | 39 | 38 | 43 |
test | 11 | 12 | 7 |
model <- cla_majority("Species", slevels)
model <- fit(model, iris_train)
train_prediction <- predict(model, iris_train)
iris_train_predictand <- adjust_class_label(iris_train[,"Species"])
train_eval <- evaluate(model, iris_train_predictand, train_prediction)
print(train_eval$metrics)
accuracy TP TN FP FN precision recall sensitivity specificity f1 1 0.3583333 0 81 0 39 NaN 0 0 1 NaN
# Test
test_prediction <- predict(model, iris_test)
iris_test_predictand <- adjust_class_label(iris_test[,"Species"])
test_eval <- evaluate(model, iris_test_predictand, test_prediction)
print(test_eval$metrics)
accuracy TP TN FP FN precision recall sensitivity specificity f1 1 0.2333333 0 19 0 11 NaN 0 0 1 NaN