Unverified Commit efa9ecf8 authored by Nick Zeng's avatar Nick Zeng Committed by GitHub
Browse files

[R-package] Update lgb.model.dt.tree.R to use keyword arguments (#3605)



* use keyword arguments

* minor style adjustment

* Update R-package/R/lgb.model.dt.tree.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>
Co-authored-by: default avatarzenggyu <zenggyu@foxmail.com>
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>
parent aabbb979
...@@ -51,11 +51,11 @@ ...@@ -51,11 +51,11 @@
lgb.model.dt.tree <- function(model, num_iteration = NULL) { lgb.model.dt.tree <- function(model, num_iteration = NULL) {
# Dump json model first # Dump json model first
json_model <- lgb.dump(model, num_iteration = num_iteration) json_model <- lgb.dump(booster = model, num_iteration = num_iteration)
# Parse json model second # Parse json model second
parsed_json_model <- jsonlite::fromJSON( parsed_json_model <- jsonlite::fromJSON(
json_model txt = json_model
, simplifyVector = TRUE , simplifyVector = TRUE
, simplifyDataFrame = FALSE , simplifyDataFrame = FALSE
, simplifyMatrix = FALSE , simplifyMatrix = FALSE
...@@ -66,7 +66,7 @@ lgb.model.dt.tree <- function(model, num_iteration = NULL) { ...@@ -66,7 +66,7 @@ lgb.model.dt.tree <- function(model, num_iteration = NULL) {
tree_list <- lapply(parsed_json_model$tree_info, single.tree.parse) tree_list <- lapply(parsed_json_model$tree_info, single.tree.parse)
# Combine into single data.table fourth # Combine into single data.table fourth
tree_dt <- data.table::rbindlist(tree_list, use.names = TRUE) tree_dt <- data.table::rbindlist(l = tree_list, use.names = TRUE)
# Substitute feature index with the actual feature name # Substitute feature index with the actual feature name
...@@ -111,7 +111,12 @@ single.tree.parse <- function(lgb_tree) { ...@@ -111,7 +111,12 @@ single.tree.parse <- function(lgb_tree) {
, leaf_count = integer(0L) , leaf_count = integer(0L)
) )
# start tree traversal # start tree traversal
pre_order_traversal(env, tree_node_leaf, current_depth, parent_index) pre_order_traversal(
env = env
, tree_node_leaf = tree_node_leaf
, current_depth = current_depth
, parent_index = parent_index
)
} else { } else {
# Check if split index is not null in leaf # Check if split index is not null in leaf
...@@ -134,14 +139,14 @@ single.tree.parse <- function(lgb_tree) { ...@@ -134,14 +139,14 @@ single.tree.parse <- function(lgb_tree) {
# Traverse tree again both left and right # Traverse tree again both left and right
pre_order_traversal( pre_order_traversal(
env env = env
, tree_node_leaf$left_child , tree_node_leaf = tree_node_leaf$left_child
, current_depth = current_depth + 1L , current_depth = current_depth + 1L
, parent_index = tree_node_leaf$split_index , parent_index = tree_node_leaf$split_index
) )
pre_order_traversal( pre_order_traversal(
env env = env
, tree_node_leaf$right_child , tree_node_leaf = tree_node_leaf$right_child
, current_depth = current_depth + 1L , current_depth = current_depth + 1L
, parent_index = tree_node_leaf$split_index , parent_index = tree_node_leaf$split_index
) )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment