Description Usage Arguments References Examples
Creates a cost-sensitive classifier by creating one classifier per pair of classes to predict cost. Takes as input a classifier accepting observation weights. The objective is to create a model that would predict the class with the minimum cost.
| 1 2 | weighted.all.pairs(X, C, classifier, predict_type_prob = "prob",
  wap_weights = TRUE, nthreads = 1, ...)
 | 
| X | The data (covariates/features). | 
| C | matrix(n_samples, n_classes) Costs for each class for each observation. | 
| classifier | function(X, y, weights=w, ...) -> object, that would create a classifier with method 'predict'. The 'y' vector passed to it is of class 'integer' with values 0/1 only. | 
| predict_type_prob | argument to pass to method 'predict' from the classifier passed to 'classifier' in order to output probabilities (must be between zero and one) instead of classes (i.e. 'predict(object, newdata, type=predict_type_prob')). | 
| wap_weights | Whether to use the weighting technique from the 'Weighted-All-Pairs' algorithm. | 
| nthreads | Number of parallel threads to use (not available on Windows systems). Note that, unlike the Python version, this is not a shared memory model and each additional thread will require more memory from the system. Not recommended to use when the algorithm is itself parallelized. | 
| ... | Extra arguments to pass to 'classifier'. | 
Beygelzimer, A., Langford, J., & Zadrozny, B. (2008). Machine learning techniques-reductions between prediction quality metrics.
| 1 2 3 4 5 6 7 8 9 10 11 | library(costsensitive)
wrapped.logistic <- function(X, y, weights, ...) {
	return(glm(y ~ ., data = X, weights = weights, family = "quasibinomial", ...))
}
set.seed(1)
X <- data.frame(feature1 = rnorm(100), feature2 = rnorm(100), feature3 = runif(100))
C <- data.frame(cost1 = rgamma(100, 1), cost2 = rgamma(100, 1), cost3 = rgamma(100, 1))
model <- weighted.all.pairs(X, C, wrapped.logistic, predict_type_prob = "response")
predict(model, X, type = "class")
predict(model, X, type = "score")
print(model)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.