Skip to content
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

Add external features to build my own metric function with Caret #32

Open
ghost opened this issue Apr 9, 2018 · 0 comments
Open

Add external features to build my own metric function with Caret #32

ghost opened this issue Apr 9, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Apr 9, 2018

I am building a classification algorithm with the Caret package. I would like to know how to add external features in the metric function to compute my own metric.

I would like to compute a score based on both the prediction (pred) and an external feature, let's call it score, which doesn't belong to the original features used by the classification algorithm.

It would give something like this:

library(caret)
library(C50)

data(iris)
dataset<-iris

compute_metric = function(data, lev = NULL, model = NULL) {
score = sum(data$pred * data$Petal.Width)
c(metric_score = score)
}

objControl =trainControl(method="repeatedcv",number=10,repeats=3,summaryFunction=compute_metric,classProbs=TRUE)

objModel <- train(x=iris[,c("Sepal.Length","Sepal.Width")], y=iris$Species,
method="C5.0",trControl=objControl,
metric="score",tuneLength=3)
However, it doesn't work.

Does anyone have an idea how to make it work?

@ghost ghost changed the title Add external features to build my own metric function on Caret Add external features to build my own metric function with Caret Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants