You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
}
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?
The text was updated successfully, but these errors were encountered:
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
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?
The text was updated successfully, but these errors were encountered: