def train_breast_cancer(config): params = LGBMEstimator(**config).params X_train = ray.get(X_train_ref) train_set = lgb.Dataset(X_train, label=y_train) gbm = lgb.train(params, train_set) preds = gbm.predict(X_test) pred_labels = np.rint(preds) tune.report(mean_accuracy=accuracy_score(y_test, pred_labels), done=True)
def evaluate_config(config): """evaluate a hyperparameter configuration""" # we uss a toy example with 2 hyperparameters metric = (round(config["x"]) - 85000)**2 - config["x"] / config["y"] # usually the evaluation takes an non-neglible cost # and the cost could be related to certain hyperparameters # in this example, we assume it's proportional to x time.sleep(config["x"] / 100000) # use tune.report to report the metric to optimize tune.report(metric=metric)
def simple_obj(config, resource=10000): config_value_vector = np.array([config["x"], config["y"], config["z"]]) score_sequence = [] for i in range(resource): a = rand_vector_unit_sphere(3) a[2] = abs(a[2]) point_projection = np.dot(config_value_vector, a) score_sequence.append(point_projection) score_avg = np.mean(np.array(score_sequence)) score_std = np.std(np.array(score_sequence)) score_lb = score_avg - 1.96 * score_std / np.sqrt(resource) tune.report(samplesize=resource, sphere_projection=score_lb)
def obj_w_intermediate_report(resource, config): config_value_vector = np.array([config["x"], config["y"], config["z"]]) score_sequence = [] for i in range(resource): a = rand_vector_unit_sphere(3) a[2] = abs(a[2]) point_projection = np.dot(config_value_vector, a) score_sequence.append(point_projection) if (i + 1) % 100 == 0: score_avg = np.mean(np.array(score_sequence)) score_std = np.std(np.array(score_sequence)) score_lb = score_avg - 1.96 * score_std / np.sqrt(i + 1) tune.report(samplesize=i + 1, sphere_projection=score_lb)
def cost(param): tune.report(loss=(param["height"] - 14) ** 2 - abs(param["width"] - 3))
def simple_func(config): tune.report(metric=(config["cost_related"]["a"] - 4)**2 * (config["b"] - 0.7)**2)
def simple_func(config): obj = (config["cost_related"]["a"] - 4)**2 \ + (config["b"] - config["cost_related"]["a"])**2 tune.report(obj=obj) tune.report(obj=obj, ab=config["cost_related"]["a"] * config["b"])