run_predict: Predict binary classification model

View source: R/modeling.R

run_predictR Documentation

Predict binary classification model

Description

Predict some representative binary classification models.

Usage

run_predict(model, .data, cutoff = 0.5)

Arguments

model

A model_df. results of fitted model that created by run_models().

.data

A tbl_df. The data set to predict the model. It also supports tbl, and data.frame objects.

cutoff

numeric. Cut-off that determines the positive from the probability of predicting the positive.

Details

Supported models are functions supported by the representative model package used in R environment. The following binary classifications are supported:

  • "logistic" : logistic regression by predict.glm() in stats package.

  • "rpart" : recursive partitioning tree model by predict.rpart() in rpart package.

  • "ctree" : conditional inference tree model by predict() in stats package.

  • "randomForest" : random forest model by predict.randomForest() in randomForest package.

  • "ranger" : random forest model by predict.ranger() in ranger package.

  • "xgboost" : random forest model by predict.xgb.Booster() in xgboost package.

  • "lasso" : random forest model by predict.glmnet() in glmnet package.

run_predict() is executed in parallel when predicting by model. However, it is not supported in MS-Windows operating system and RStudio environment.

Value

model_df. results of predicted model. model_df is composed of tbl_df and contains the following variables.:

  • step : character. The current stage in the model fit process. The result of calling run_predict() is returned as "2.Predicted".

  • model_id : character. Type of fit model.

  • target : character. Name of target variable.

  • is_factor : logical. Indicates whether the target variable is a factor.

  • positive : character. Level of positive class of binary classification.

  • negative : character. Level of negative class of binary classification.

  • fitted_model : list. Fitted model object.

  • predicted : list. Predicted value by individual model. Each value has a predict_class class object.

Examples

library(dplyr)

# Divide the train data set and the test data set.
sb <- rpart::kyphosis %>%
  split_by(Kyphosis)

# Extract the train data set from original data set.
train <- sb %>%
  extract_set(set = "train")

# Extract the test data set from original data set.
test <- sb %>%
  extract_set(set = "test")

# Sampling for unbalanced data set using SMOTE(synthetic minority over-sampling technique).
train <- sb %>%
  sampling_target(seed = 1234L, method = "ubSMOTE")

# Cleaning the set.
train <- train %>%
  cleanse

# Run the model fitting.
result <- run_models(.data = train, target = "Kyphosis", positive = "present")
result

# Run the several kinds model predict by dplyr
result %>%
  run_predict(test)


alookr documentation built on May 29, 2024, 10:38 a.m.