I am trying to run this julia script The goal consists in finding best parameters tuning for a XGBoost Regressor model
using MLJ, MLJXGBoostInterface, MLJTuning, Random, XGBoost
# Load the XGBoost Regressor model
XGBoostRegressor = @load XGBoostRegressor
# Generate synthetic regression dataset
X, y = MLJ.make_regression(200, 5; noise=0.3, rng=1234)
train, test = partition(eachindex(y), 0.8, shuffle=true, rng=1234)
# Define the base model with placeholders for hyperparameters
model = XGBoostRegressor(
objective="reg:squarederror",
eta=0.1, # Learning rate
max_depth=6, # Tree depth
num_round=100, # Boosting rounds
)
# Define the hyperparameter tuning ranges
tuned_model = TunedModel(
model=model,
tuning=RandomSearch(),
resampling=CV(nfolds=5, shuffle=true, rng=1234),
range=[
:eta => range(0.01, 0.3, length=5),
:max_depth => 2:10,
:num_round => range(50, 200, length=4)
],
measure=rms,
n=10,
acceleration=CPUThreads()
);
# Wrap the model into a machine
mach = machine(tuned_model, X, y);
# Train the tuned model
fit!(mach, rows=train);
But at this point julia returns:
┌ Error: Problem fitting the machine machine(DeterministicTunedModel(model = XGBoostRegressor(test = 1, …), …), …).
└ @ MLJBase ~/.julia/packages/MLJBase/7nGJF/src/machines.jl:694
[ Info: Running type checks...
[ Info: Type checks okay.
ERROR: ArgumentError: Unsupported range #2.
Does anyone have an idea about what is causing this error?
I am trying to run this julia script The goal consists in finding best parameters tuning for a XGBoost Regressor model
using MLJ, MLJXGBoostInterface, MLJTuning, Random, XGBoost
# Load the XGBoost Regressor model
XGBoostRegressor = @load XGBoostRegressor
# Generate synthetic regression dataset
X, y = MLJ.make_regression(200, 5; noise=0.3, rng=1234)
train, test = partition(eachindex(y), 0.8, shuffle=true, rng=1234)
# Define the base model with placeholders for hyperparameters
model = XGBoostRegressor(
objective="reg:squarederror",
eta=0.1, # Learning rate
max_depth=6, # Tree depth
num_round=100, # Boosting rounds
)
# Define the hyperparameter tuning ranges
tuned_model = TunedModel(
model=model,
tuning=RandomSearch(),
resampling=CV(nfolds=5, shuffle=true, rng=1234),
range=[
:eta => range(0.01, 0.3, length=5),
:max_depth => 2:10,
:num_round => range(50, 200, length=4)
],
measure=rms,
n=10,
acceleration=CPUThreads()
);
# Wrap the model into a machine
mach = machine(tuned_model, X, y);
# Train the tuned model
fit!(mach, rows=train);
But at this point julia returns:
┌ Error: Problem fitting the machine machine(DeterministicTunedModel(model = XGBoostRegressor(test = 1, …), …), …).
└ @ MLJBase ~/.julia/packages/MLJBase/7nGJF/src/machines.jl:694
[ Info: Running type checks...
[ Info: Type checks okay.
ERROR: ArgumentError: Unsupported range #2.
Does anyone have an idea about what is causing this error?
Share Improve this question asked Mar 30 at 17:20 AndreaAndrea 7133 silver badges9 bronze badges1 Answer
Reset to default -1For a field sampler "pair of the form (field, s)
"
- use Tuple syntax, like
(:fieldname, s)
- not Pair syntax, like
:fieldname => s
MLJTuning.RandomSearch