Skip to content

Commit

Permalink
rpart2, svm rbf works
Browse files Browse the repository at this point in the history
  • Loading branch information
Begum Topcuoglu committed Aug 20, 2020
1 parent 349058a commit 6c33480
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 70 deletions.
9 changes: 5 additions & 4 deletions R/cross_val.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ define_cv <- function(train_data, outcome_colname, kfold = 5, cv_times = 100, se
kfold,
times = cv_times
)

seeds <- get_seeds_trainControl(kfold, cv_times, ncol(train_data))
#TODO there is something wrong with the seed calculation
# SVM radial is giving an error on seeds if we use this
#seeds <- get_seeds_trainControl(kfold, cv_times, ncol(train_data))

ncol(train_data) - 1
cv <- caret::trainControl(
Expand All @@ -32,8 +33,8 @@ define_cv <- function(train_data, outcome_colname, kfold = 5, cv_times = 100, se
classProbs = TRUE,
summaryFunction = caret::twoClassSummary,
indexFinal = NULL,
savePredictions = TRUE,
seeds = seeds
savePredictions = TRUE
#,seeds = seeds
)
return(cv)
}
Expand Down
19 changes: 11 additions & 8 deletions data-raw/otu_medium.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
## code to prepare `otu_medium` dataset goes here
otu_medium <- read.delim("data-raw/otu_medium.csv", sep = ",")
otu_large <- read.delim("data-raw/otu_large.csv", sep = ",")
otu_medium <- otu_large[1:200,1:200]
usethis::use_data(otu_medium, overwrite = TRUE)
otu_med_results4 <- mikRopML::run_ml(otu_medium,
"rpart2",
outcome_colname = "dx",
outcome_value = "cancer",
hyperparameters = mikRopML::default_hyperparams,
find_feature_importance = FALSE,
seed = 2019
otu_med_results <- mikRopML::run_ml(otu_medium,
"rpart2",
outcome_colname = "dx",
outcome_value = "cancer",
hyperparameters = mikRopML::test_hyperparams,
find_feature_importance = FALSE,
seed = 2019,
kfold = as.integer(3)
)
usethis::use_data(otu_med_results, overwrite = TRUE)
16 changes: 1 addition & 15 deletions data-raw/otu_mini.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,8 @@ otu_mini_results3 <- mikRopML::run_ml(otu_mini,
seed = 2019,
kfold = 2
)
# usethis::use_data(otu_mini_results3, overwrite = TRUE)
usethis::use_data(otu_mini_results3, overwrite = TRUE)

# TODO: fix error:
# Error in { :
# task 1 failed - "need at least two non-NA values to interpolate"
# In addition: There were 50 or more warnings (use warnings() to see the first 50)
# otu_mini_results4 <- mikRopML::run_ml(otu_mini,
# "rpart2",
# outcome_colname = "dx",
# outcome_value = "cancer",
# hyperparameters = mikRopML::test_hyperparams,
# find_feature_importance = FALSE,
# seed = 2019,
# kfold = 2
# )
# usethis::use_data(otu_mini_results4, overwrite = TRUE)

otu_mini_results5 <- mikRopML::run_ml(otu_mini,
"xgbTree",
Expand Down
Binary file added data/otu_med_results.rda
Binary file not shown.
Binary file modified data/otu_medium.rda
Binary file not shown.
Binary file modified data/otu_mini.rda
Binary file not shown.
Binary file modified data/otu_mini_cv5.rda
Binary file not shown.
Binary file modified data/otu_mini_results1.rda
Binary file not shown.
Binary file modified data/otu_mini_results2.rda
Binary file not shown.
Binary file modified data/otu_mini_results3.rda
Binary file not shown.
Binary file modified data/otu_mini_results5.rda
Binary file not shown.
Binary file modified data/test_data_mini.rda
Binary file not shown.
Binary file modified data/test_hyperparams.rda
Binary file not shown.
Binary file modified data/train_data_mini.rda
Binary file not shown.
Binary file modified data/trained_model_mini.rda
Binary file not shown.
86 changes: 43 additions & 43 deletions tests/testthat/test-run_ml.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,49 +60,49 @@ test_that("run_ml works for random forest", {
tol = 1e-3
)
})
# test_that("run_ml works for svmRadial", {
# expect_equal_ml_results(
# mikRopML::run_ml(otu_mini,
# "svmRadial",
# outcome_colname = "dx",
# outcome_value = "cancer",
# hyperparameters = mikRopML::test_hyperparams,
# find_feature_importance = FALSE,
# seed = 2019,
# kfold = as.integer(2)
# ),
# otu_mini_results3
# )
# })
# test_that("run_ml works for rpart2", {
# expect_equal_ml_results(
# mikRopML::run_ml(otu_mini,
# "rpart2",
# outcome_colname = "dx",
# outcome_value = "cancer",
# hyperparameters = mikRopML::test_hyperparams,
# find_feature_importance = FALSE,
# seed = 2019,
# kfold = as.integer(3)
# ),
# otu_mini_results4
# )
# })
test_that("run_ml works for xgbTree", {
expect_equal_ml_results(
mikRopML::run_ml(otu_mini,
"xgbTree",
outcome_colname = "dx",
outcome_value = "cancer",
hyperparameters = mikRopML::test_hyperparams,
find_feature_importance = FALSE,
seed = 2019,
kfold = as.integer(2)
),
otu_mini_results5,
tol = 1e-3
)
})
test_that("run_ml works for svmRadial", {
expect_equal_ml_results(
mikRopML::run_ml(otu_mini,
"svmRadial",
outcome_colname = "dx",
outcome_value = "cancer",
hyperparameters = mikRopML::test_hyperparams,
find_feature_importance = FALSE,
seed = 2019,
kfold = as.integer(2)
),
otu_mini_results3
)
})
test_that("run_ml works for rpart2", {
expect_equal_ml_results(
mikRopML::run_ml(otu_medium,
"rpart2",
outcome_colname = "dx",
outcome_value = "cancer",
hyperparameters = mikRopML::test_hyperparams,
find_feature_importance = FALSE,
seed = 2019,
kfold = as.integer(3)
),
otu_med_results
)
})
#test_that("run_ml works for xgbTree", {
# expect_equal_ml_results(
# mikRopML::run_ml(otu_mini,
# "xgbTree",
# outcome_colname = "dx",
# outcome_value = "cancer",
# hyperparameters = mikRopML::test_hyperparams,
# find_feature_importance = FALSE,
# seed = 2019,
# kfold = as.integer(2)
# ),
# otu_mini_results5,
# tol = 1e-3
# )
#})
test_that("run_ml errors for unsupported method", {
expect_error(
run_ml(
Expand Down

0 comments on commit 6c33480

Please sign in to comment.