M
megjosh
Guest
megjosh Asks: How to specify scale_pos_weight value at runtime in Hyperopt?
I want to use LighgbmClassifier for a binary Classification. for Hyper Parameter tuning I want to use Hyperopt. The Dataset is imbalanced. Using Sklearns class_weight.compute_class_weight as shown below
The following is the space parameter that I am passing to the objective function
My question will the following set scale_pos_weight properly in the space dictionary
If that is wrong then what would be the correct way to set scale_pos_weight at runtime in the space dictionary that is passed to the Objective fn that is in turn passed to the fmin of Hyperopt.
Thanks for your help and answers.
I want to use LighgbmClassifier for a binary Classification. for Hyper Parameter tuning I want to use Hyperopt. The Dataset is imbalanced. Using Sklearns class_weight.compute_class_weight as shown below
Code:
clas_wts_arr = class_weight.compute_class_weight('balanced',np.unique(y_trn),y_trn)
self.scale_pos_wt = clas_wts_arr[0] / clas_wts_arr[1]
The following is the space parameter that I am passing to the objective function
Code:
space = {'objective' : hp.choice('objective', objective_list),
'boosting' : hp.choice('boosting', boosting_list),
'metric' : hp.choice('metric', metric_list),
"max_depth": hp.quniform("max_depth", 1, 15,2),
'min_data_in_leaf': hp.quniform('min_data_in_leaf', 1, 256, 1),
'num_leaves': hp.quniform('num_leaves', 7, 150, 1),
'feature_fraction' : hp.quniform('feature_fraction', 0.5, 1, 0.01),
'min_gain_to_split' : hp.quniform('min_gain_to_split', 0.1, 5, 0.01),
'lambda_l1' : hp.uniform('lambda_l1', 0, 5),
'lambda_l2' : hp.uniform('lambda_l2', 0, 5),
'feature_pre_filter': False}
My question will the following set scale_pos_weight properly in the space dictionary
Code:
#set scale pos weight explicitly
space['scale_pos_weight'] = self.scale_pos_wt
If that is wrong then what would be the correct way to set scale_pos_weight at runtime in the space dictionary that is passed to the Objective fn that is in turn passed to the fmin of Hyperopt.
Thanks for your help and answers.
SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.