Learn R Programming

PatientLevelPrediction (version 6.4.1)

sklearnToJson: Saves sklearn python model object to json in path

Description

Saves sklearn python model object to json in path

Usage

sklearnToJson(model, path)

Value

nothing, saves the model to the path as json

Arguments

model

a fitted sklearn python model object

path

path to the saved model file

Examples

Run this code
 # dontrun reason: requires python environment with sklearn 
if (FALSE) { 
sklearn <- reticulate::import("sklearn", convert = FALSE)
model <- sklearn$tree$DecisionTreeClassifier()
model$fit(sklearn$datasets$load_iris()$data, sklearn$datasets$load_iris()$target)
saveLoc <- file.path(tempdir(), "model.json")
sklearnToJson(model, saveLoc)
# the model.json is saved in the tempdir
dir(tempdir())
# clean up
unlink(saveLoc)
}

Run the code above in your browser using DataLab