-
Notifications
You must be signed in to change notification settings - Fork 632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update on LFDA using new lfda package on CRAN #219
Conversation
It looks like you have an error in your tests. |
Yeah I wasn't able to figure out why. Let me know if you found anything I missed. |
Since you now have these functions in your own R package, I'm not sure why you are still committing to this package. |
@topepo He needs to revise the lfda model in caret to use his new package |
@@ -53,5 +53,6 @@ Suggests: | |||
superpc, | |||
Cubist, | |||
testthat (>= 0.9.1), | |||
rARPACK | |||
rARPACK, | |||
lfda |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this import. We don't want caret to depend on modeling packages.
@terrytangyuan Please delete the |
@topepo This PR should remove all lfda-related code, as it's migrated to @terrytangyuan's new package on CRAN. |
@terrytangyuan You can also add a lfda.R file to the models section so it can be run in base caret. Inside that file you can specify that the model depends on the new lfda package. |
@zachmayer Just double check: so I should remove all dependencies and code related to lfda and then write a new file to the models section, correct? |
Correct. That's the preferred way to add new models to caret: no code or dependencies live inside the package, just a custom model definition that tells caret which model to load. |
@zachmayer I tried adding |
On this PR, edit the .travis.yml file. Find this line:
This will install lfda from github. Then you'll need to add @export
@method predict lfda Here's what the full roxygen2 block for lfda might look like: @title predict.lfda
@description make predictions for new data from an lfda object
@param object An lfda object
@param newdata Data to use for predictions
@param ... ignored |
@@ -1,4 +1,5 @@ | |||
library(caret) | |||
library(lfda) | |||
library(testthat) | |||
|
|||
test_that('test lfda model training and prediction', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should move to your own package, as it JUST tests the lfda model.
Finally, tests for test_that('test lfda model training and prediction', {
skip_on_cran()
set.seed(1)
tr_dat <- twoClassSim(200)
te_dat <- twoClassSim(200)
model <- train(
Class~., tr_dat,
method = "lfda",
trControl = trainControl(method='cv', number='5')
)
expect_is(model, 'train')
expect_is(model$finalModel, 'lfda')
expect_is(model$results$Accuracy, 'numeric')
expect_true(model$results$Accuracy >= .75)
}) |
library = c("lfda"), | ||
type = "Classification", | ||
grid = function(x, y, len = NULL) { | ||
stop("grid is not available for lfda. ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is always going to cause your model to fail. Caret models ALWAYS need a grid. See here for a simple modelInfo
you can copy: https://github.com/terrytangyuan/caret/blob/newlfda/models/files/lda.R
Also, take a quick read through here: http://topepo.github.io/caret/custom_models.html |
Thank you! These are very helpful. I'll read through and revise this. I've missed a lot of stuff. |
@zachmayer I kept getting this |
You need to re-run the script to create the models data object: https://github.com/topepo/caret/blob/master/models/parseModels.R |
Ok, we'll see if this build passes on master and I'll make a PR to fix it. |
For future reference, you need to keep your fork up-to-date with topepo/caret master. This will reduce the likelihood of merge conflicts on future PRs. Basically, what happened was Max added a new model at the same time you did. This created a conflict. The resolution of the conflict is to merge mx's branch into yours and re-create |
For future reference, you can test your model as follows: modelInfo <- list(label = "Local Fisher Discriminant Analysis",
library = c("lfda"),
type = "Classification",
grid = function(x, y, len = NULL, search = "grid") data.frame(r="none",metric="none", knn="none"),
parameters = data.frame(parameter = c("r", "metric", "knn"),
class = c("numeric", "character", "numeric"),
label = c("# Reduced Dimensions",
"Type of Transformation Metric",
"# of Nearest Neighbors")),
fit = function(x, y, param, ...) {
theDots <- list(...)
argList <- list(x = x, y = y, r = ifelse(is.null(param$r, 3, param$r)),
metric = ifelse(is.null(param$metric), "plain", param$metric),
knn = ifelse(is.null(param$knn, 5, param$knn)))
argList <- c(argList, theDots)
if(is.data.frame(x)) x <- as.matrix(x)
out <- do.call("lfda", argList)
out$call <- NULL
out
},
# predict = function(modelFit, newdata, submodels = NULL)
# predict(modelFit, newdata),
prob = NULL,
predictors = function(x, ...) {
# if dimensionality of original data is not reduced
if(dim(x$T)[1]==dim(x$T)[2]){
return(colnames(x$Z))
} else {
print("predictors are not available for lfda model with dimension reduction. ")
return(NULL)
}
},
tags = c("Metric Learning", "Local Metric Learning", "Dimension Reduction",
"Multimodality Preservance", "Fisher Discriminant Analysis",
"Classification", "Pre-processing")
)
library(lfda)
tr_dat <- twoClassSim(200)
te_dat <- twoClassSim(200)
lfda.model <- train(
x=tr_dat[,-16],y=tr_dat[,16],
method = modelInfo
) As you can see this fails. Digging deeper, we can see the fit function is failing: modelInfo$fit(tr_dat[,-16], tr_dat[,16], modelInfo$grid(1)) I'm making a PR to fix this, but in the future you need to test your models and make sure they work before submitting them. You get a freebie this time since there were git issues to work out =D Next time you should be able to do this on your own. |
I can't actually get lfda to run on any input data: 5 stop("'x' must be an array of at least two dimensions")
4 colSums(Xc^2)
3 as.matrix(colSums(Xc^2))
2 t(as.matrix(colSums(Xc^2)))
1 lfda(matrix(runif(100), ncol = 10), runif(10), r = 3) Can you send me an example of how to run lfda, e.g. on the iris dataset? |
I am not by my pc but you can check the tests in lfda package.
|
What data type do the arguments to lfda need to be? |
Ok, go it figured out. PR coming tongiht. |
Thanks! And yep I got the lesson. |
No description provided.