Skip to content

Commit 5f4c3fd

Browse files
committed
add test
1 parent 98f4d4a commit 5f4c3fd

File tree

6 files changed

+1031
-6
lines changed

6 files changed

+1031
-6
lines changed

.ci/test.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,35 @@ fi
6868
# other implementations like pypy
6969
CONDA_PYTHON_REQUIREMENT="python=${PYTHON_VERSION}[build=*_cp*]"
7070

71+
if_else_test() {
72+
cd "$BUILD_DIRECTORY/tests/cpp_tests"
73+
74+
mv ../../src/boosting/gbdt_prediction.cpp ../../src/boosting/gbdt_prediction.cpp.bak
75+
../../lightgbm_org config=$1 convert_model_language=cpp convert_model=../../src/boosting/gbdt_prediction.cpp
76+
../../lightgbm_org config=$2 output_result=origin.pred
77+
78+
cd "$BUILD_DIRECTORY"
79+
cmake -B build -S . || exit 1
80+
cmake --build build --target lightgbm -j4 || exit 1
81+
cd "$BUILD_DIRECTORY/tests/cpp_tests"
82+
../../lightgbm config=$2 output_result=ifelse.pred
83+
84+
python test.py
85+
86+
mv ../../src/boosting/gbdt_prediction.cpp.bak ../../src/boosting/gbdt_prediction.cpp
87+
cd "$BUILD_DIRECTORY"
88+
}
89+
7190
if [[ $TASK == "if-else" ]]; then
7291
conda create -q -y -n "${CONDA_ENV}" "${CONDA_PYTHON_REQUIREMENT}" numpy
7392
# shellcheck disable=SC1091
7493
source activate "${CONDA_ENV}"
94+
7595
cmake -B build -S . || exit 1
7696
cmake --build build --target lightgbm -j4 || exit 1
77-
cd "$BUILD_DIRECTORY/tests/cpp_tests"
78-
../../lightgbm config=train.conf convert_model_language=cpp convert_model=../../src/boosting/gbdt_prediction.cpp
79-
../../lightgbm config=predict.conf output_result=origin.pred
80-
../../lightgbm config=predict.conf output_result=ifelse.pred
81-
python test.py
97+
mv lightgbm lightgbm_org
98+
if_else_test "train.conf" "predict.conf"
99+
if_else_test "train_nan_input.conf" "predict_nan_input.conf"
82100
exit 0
83101
fi
84102

src/boosting/gbdt_prediction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ void GBDT::PredictLeafIndexByMap(const std::unordered_map<int, double>& features
9494
}
9595
}
9696

97-
} // namespace LightGBM
97+
} // namespace LightGBM
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
tree
2+
version=v4
3+
num_class=1
4+
num_tree_per_iteration=1
5+
label_index=0
6+
max_feature_idx=9
7+
objective=regression
8+
feature_names=feature1 feature2 feature3 feature4 feature5 feature6 feature7 feature8 feature9 feature10
9+
feature_infos=[0.0030208713561612477:0.9966832779346797] [3.0718845382415871e-05:0.99971767328613059] [1.1634755366141114e-05:0.99889261203329061] [0.00040154402533987277:0.99946068105967312] [0.0013536257154681541:0.99941372577066656] [0.00022703821825553749:0.99890469976307672] [0.00041028943917487126:0.99413936122116753] [5.2826932296801132e-05:0.99762829740215653] [0.00090583524609022525:0.99742293905355417] [0.0011120941961874076:0.99955770325043858]
10+
tree_sizes=394 402 402
11+
12+
Tree=0
13+
num_leaves=3
14+
num_cat=0
15+
split_feature=1 2
16+
split_gain=151 67.4877
17+
threshold=0.43908158089896321 0.50555253269984324
18+
decision_type=10 8
19+
left_child=-1 -2
20+
right_child=1 -3
21+
leaf_value=0.3177485457277795 0.44806984060967808 0.36627160319740354
22+
leaf_weight=395 190 215
23+
leaf_count=395 190 215
24+
internal_value=0.36174 0.404646
25+
internal_weight=0 405
26+
internal_count=800 405
27+
is_linear=0
28+
shrinkage=1
29+
30+
31+
Tree=1
32+
num_leaves=3
33+
num_cat=0
34+
split_feature=2 0
35+
split_gain=80.9689 24.6402
36+
threshold=0.47134327177395619 1.0000000180025095e-35
37+
decision_type=8 10
38+
left_child=1 -1
39+
right_child=-2 -3
40+
leaf_value=-0.036787212124237648 -0.026726479674212891 0.047840481589521179
41+
leaf_weight=39 469 292
42+
leaf_count=39 469 292
43+
internal_value=0 0.0378692
44+
internal_weight=0 331
45+
internal_count=800 331
46+
is_linear=0
47+
shrinkage=0.1
48+
49+
50+
Tree=2
51+
num_leaves=3
52+
num_cat=0
53+
split_feature=1 0
54+
split_gain=120.883 23.018
55+
threshold=0.46947632301562686 1.0000000180025095e-35
56+
decision_type=10 10
57+
left_child=-1 -2
58+
right_child=1 -3
59+
leaf_value=-0.037347034887016677 -0.036852757930755618 0.048212644289095129
60+
leaf_weight=416 35 349
61+
leaf_count=416 35 349
62+
internal_value=0 0.0404593
63+
internal_weight=0 384
64+
internal_count=800 384
65+
is_linear=0
66+
shrinkage=0.1
67+
68+
69+
end of trees
70+
71+
feature_importances:
72+
feature1=2
73+
feature2=2
74+
feature3=2
75+
76+
parameters:
77+
[boosting: gbdt]
78+
[objective: regression]
79+
[metric: l2]
80+
[tree_learner: serial]
81+
[device_type: cpu]
82+
[data_sample_strategy: bagging]
83+
[data: ]
84+
[valid: ]
85+
[num_iterations: 3]
86+
[learning_rate: 0.1]
87+
[num_leaves: 3]
88+
[num_threads: 0]
89+
[seed: 0]
90+
[deterministic: 0]
91+
[force_col_wise: 0]
92+
[force_row_wise: 0]
93+
[histogram_pool_size: -1]
94+
[max_depth: -1]
95+
[min_data_in_leaf: 20]
96+
[min_sum_hessian_in_leaf: 0.001]
97+
[bagging_fraction: 1]
98+
[pos_bagging_fraction: 1]
99+
[neg_bagging_fraction: 1]
100+
[bagging_freq: 0]
101+
[bagging_seed: 3]
102+
[feature_fraction: 0.9]
103+
[feature_fraction_bynode: 1]
104+
[feature_fraction_seed: 2]
105+
[extra_trees: 0]
106+
[extra_seed: 6]
107+
[early_stopping_round: 0]
108+
[early_stopping_min_delta: 0]
109+
[first_metric_only: 0]
110+
[max_delta_step: 0]
111+
[lambda_l1: 0]
112+
[lambda_l2: 0]
113+
[linear_lambda: 0]
114+
[min_gain_to_split: 0]
115+
[drop_rate: 0.1]
116+
[max_drop: 50]
117+
[skip_drop: 0.5]
118+
[xgboost_dart_mode: 0]
119+
[uniform_drop: 0]
120+
[drop_seed: 4]
121+
[top_rate: 0.2]
122+
[other_rate: 0.1]
123+
[min_data_per_group: 100]
124+
[max_cat_threshold: 32]
125+
[cat_l2: 10]
126+
[cat_smooth: 10]
127+
[max_cat_to_onehot: 4]
128+
[top_k: 20]
129+
[monotone_constraints: ]
130+
[monotone_constraints_method: basic]
131+
[monotone_penalty: 0]
132+
[feature_contri: ]
133+
[forcedsplits_filename: ]
134+
[refit_decay_rate: 0.9]
135+
[cegb_tradeoff: 1]
136+
[cegb_penalty_split: 0]
137+
[cegb_penalty_feature_lazy: ]
138+
[cegb_penalty_feature_coupled: ]
139+
[path_smooth: 0]
140+
[interaction_constraints: ]
141+
[verbosity: -1]
142+
[saved_feature_importance_type: 0]
143+
[use_quantized_grad: 0]
144+
[num_grad_quant_bins: 4]
145+
[quant_train_renew_leaf: 0]
146+
[stochastic_rounding: 1]
147+
[linear_tree: 0]
148+
[max_bin: 255]
149+
[max_bin_by_feature: ]
150+
[min_data_in_bin: 3]
151+
[bin_construct_sample_cnt: 200000]
152+
[data_random_seed: 1]
153+
[is_enable_sparse: 1]
154+
[enable_bundle: 1]
155+
[use_missing: 1]
156+
[zero_as_missing: 0]
157+
[feature_pre_filter: 1]
158+
[pre_partition: 0]
159+
[two_round: 0]
160+
[header: 0]
161+
[label_column: ]
162+
[weight_column: ]
163+
[group_column: ]
164+
[ignore_column: ]
165+
[categorical_feature: ]
166+
[forcedbins_filename: ]
167+
[precise_float_parser: 0]
168+
[parser_config_file: ]
169+
[objective_seed: 5]
170+
[num_class: 1]
171+
[is_unbalance: 0]
172+
[scale_pos_weight: 1]
173+
[sigmoid: 1]
174+
[boost_from_average: 1]
175+
[reg_sqrt: 0]
176+
[alpha: 0.9]
177+
[fair_c: 1]
178+
[poisson_max_delta_step: 0.7]
179+
[tweedie_variance_power: 1.5]
180+
[lambdarank_truncation_level: 30]
181+
[lambdarank_norm: 1]
182+
[label_gain: ]
183+
[lambdarank_position_bias_regularization: 0]
184+
[eval_at: ]
185+
[multi_error_top_k: 1]
186+
[auc_mu_weights: ]
187+
[num_machines: 1]
188+
[local_listen_port: 12400]
189+
[time_out: 120]
190+
[machine_list_filename: ]
191+
[machines: ]
192+
[gpu_platform_id: -1]
193+
[gpu_device_id: -1]
194+
[gpu_use_dp: 0]
195+
[num_gpu: 1]
196+
197+
end of parameters
198+
199+
pandas_categorical:[]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
data=../data/regression_with_nan_input.csv
2+
3+
input_model=LightGBM_model_for_if_else_test.txt
4+
5+
task=predict

tests/cpp_tests/train_nan_input.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
task=convert_model
2+
3+
input_model=LightGBM_model_for_if_else_test.txt

0 commit comments

Comments
 (0)