Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,40 @@ | ||
# Test F1 score | ||
### Test F1 score | ||
rxOptions(reportProgress=0) | ||
|
||
context("F1 score") | ||
|
||
|
||
# ------------------------------------------------------------------------ | ||
|
||
test_that("rxF1score works with data frame",{ | ||
dat <- data.frame(iris[, -5], Virg = iris$Species == "virginica") | ||
fit <- suppressWarnings( | ||
rxLogit(Virg ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, | ||
dat) | ||
) | ||
prd <- rxPredict(fit, dat)$Virg_Pred | ||
cmb <- data.frame(Virg=dat$Virg, Pred=prd) | ||
tst <- rxF1score("Virg", "Pred", cmb) | ||
dat <- data.frame(iris[, -5], Vers = iris$Species == "versicolor") | ||
fit <- rxLogit(Vers ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, dat) | ||
prd <- rxPredict(fit, dat)$Vers_Pred | ||
cmb <- data.frame(Vers=dat$Vers, Pred=prd) | ||
tst <- rxF1score("Vers", "Pred", cmb) | ||
|
||
expect_is(tst, "list") | ||
expect_equal(names(tst), c("precision", "recall", "trueNegRate", "accuracy", "F1")) | ||
expect_equivalent(unname(unlist(tst)), c(0.98, 0.98, 0.99, 0.98666667, 0.98)) | ||
expect_equal(unname(unlist(tst)), c(0.641025641025641, 0.5, 0.86, 0.74, 0.561797752808989)) | ||
}) | ||
|
||
|
||
# ------------------------------------------------------------------------ | ||
|
||
test_that("rxF1score works with XDF",{ | ||
dataFile <- tempfile(pattern = ".data", fileext = ".xdf") | ||
dat <- data.frame(iris[, -5], Virg = iris$Species == "virginica") | ||
dat <- data.frame(iris[, -5], Vers = iris$Species == "versicolor") | ||
rxDataStep(dat, outFile=dataFile, rowsPerRead=50) | ||
fit <- suppressWarnings( | ||
rxLogit(Virg ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, | ||
rxLogit(Vers ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, | ||
dat) | ||
) | ||
prd <- rxPredict(fit, dat)$Virg_Pred | ||
cmb <- data.frame(Virg=dat$Virg, Pred=prd) | ||
tst <- rxF1score("Virg", "Pred", cmb) | ||
prd <- rxPredict(fit, dat)$Vers_Pred | ||
cmb <- data.frame(Vers=dat$Vers, Pred=prd) | ||
tst <- rxF1score("Vers", "Pred", cmb) | ||
|
||
expect_is(tst, "list") | ||
expect_equal(names(tst), c("precision", "recall", "trueNegRate", "accuracy", "F1")) | ||
expect_equivalent(unname(unlist(tst)), c(0.98, 0.98, 0.99, 0.98666667, 0.98)) | ||
expect_equal(unname(unlist(tst)), c(0.641025641025641, 0.5, 0.86, 0.74, 0.561797752808989)) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
# Test For the rxLinPredError() function | ||
rxOptions(reportProgress=0) | ||
|
||
context("MSE, MAPE, MPE, MSWD") | ||
context("rxLinPredError") | ||
|
||
test_that("rxLinPredError works with data frame",{ | ||
dat <- data.frame(actual = c(1.264896, 1.964210, 2.671872, 3.838703, 5.252300), | ||
pred = 1:5, weights = rep(1, 5)) | ||
tst <- rxLinPredError("actual", "pred", dat, "weights") | ||
tst <- rxLinPredError("actual", "pred", dat, "weights", reportProgress=0) | ||
expect_is(tst, "list") | ||
expect_equal(names(tst), c("MAPE", "MPE", "MSE", "MSWD")) | ||
expect_equivalent(unname(unlist(tst)), c(0.08810105, -0.01488186, 0.05375816, 1.07516325)) | ||
}) | ||
|
||
test_that("rxLinPredError works with XDF",{ | ||
dataFile <- tempfile(pattern = ".data", fileext = ".xdf") | ||
on.exit({ | ||
file.remove(dataFile) | ||
}) | ||
dat <- data.frame(actual = c(1.264896, 1.964210, 2.671872, 3.838703, 5.252300), | ||
pred = 1:5, weights = rep(1, 5)) | ||
rxDataStep(dat, outFile=dataFile, rowsPerRead=50) | ||
tst <- rxLinPredError("actual", "pred", dataFile, "weights") | ||
rxDataStep(dat, outFile=dataFile, rowsPerRead=50, reportProgress=0) | ||
tst <- rxLinPredError("actual", "pred", dataFile, "weights", reportProgress=0) | ||
expect_is(tst, "list") | ||
expect_equal(names(tst), c("MAPE", "MPE", "MSE", "MSWD")) | ||
expect_equivalent(unname(unlist(tst)), c(0.08810105, -0.01488186, 0.05375816, 1.07516325)) | ||
file.remove(dataFile) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
### Test rxMoments | ||
rxOptions(reportProgress=0) | ||
|
||
context("rxMoments") | ||
|
||
|
||
# ------------------------------------------------------------------------ | ||
|
||
test_that("rxMoments works with data frame",{ | ||
stopifnot(require("e1071")) | ||
tst <- rxMoments(~Sepal.Length, iris) | ||
|
||
g1 <- skewness(iris$Sepal.Length, type=1) | ||
G1 <- skewness(iris$Sepal.Length, type=2) | ||
b1 <- skewness(iris$Sepal.Length, type=3) | ||
|
||
expect_equal(g1, tst[["skewness"]][["g1"]]) | ||
expect_equal(G1, tst[["skewness"]][["G1"]]) | ||
expect_equal(b1, tst[["skewness"]][["b1"]]) | ||
|
||
g2 <- kurtosis(iris$Sepal.Length, type=1) | ||
G2 <- kurtosis(iris$Sepal.Length, type=2) | ||
b2 <- kurtosis(iris$Sepal.Length, type=3) | ||
expect_equal(g2, tst[["kurtosis"]][["g2"]]) | ||
expect_equal(G2, tst[["kurtosis"]][["G2"]]) | ||
expect_equal(b2, tst[["kurtosis"]][["b2"]]) | ||
|
||
}) | ||
|
||
|