Issue
I'm currently working to set up a randomized search to help find the best parameters for a model. But I've hit an error that I can't find anywhere on google: Missing positional argument 'x' in the .fit function for the randomized search model.
This is what the code for my model and randomized search model look like.
# Build model
def build_model(il_neurons=100, hl_neurons=50, num_hl=10):
model = Sequential()
model.add(Dense(il_neurons, input_dim=num_inputs, activation='relu'))
for i in range(num_hl):
model.add(Dense(hl_neurons, activation='relu'))
model.add(Dense(1))
model.compile(optimizer=optimizer, loss="mean_squared_error", metrics=[RootMeanSquaredError()])
return model
'''Random Search Model'''
# Parameters
il_neurons = range(75, 151, 5)
hl_neurons = range(10, 61, 3)
num_hl = range(1, 16, 1)
parameters = {"model__il_neurons": il_neurons,
"model__hl_neurons": hl_neurons,
"model__num_hl": num_hl}
# Model
model = KerasRegressor(build_fn=build_model)
rscv_model = RandomizedSearchCV(estimator=model,
param_distributions=parameters,
n_iter=20,
scoring='neg_root_mean_squared_error',
cv=kfold,
n_jobs=-1,
verbose=0)
history = rscv_model.fit(x=X_train_pca,
y=y_train,
validation_split=0.1,
epochs=epochs,
batch_size=batch_size,
callbacks=callbacks,
shuffle=True,
verbose=0)
Running that same model on it's own doesn't throw any errors. Works totally fine. But running the random search model code gives this error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/tmp/ipykernel_41/3876581477.py in <module>
28 callbacks=callbacks,
29 shuffle=True,
---> 30 verbose=0)
31
32 print("Best Parameters:")
/opt/conda/lib/python3.7/site-packages/sklearn/utils/validation.py in inner_f(*args, **kwargs)
70 FutureWarning)
71 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 72 return f(**kwargs)
73 return inner_f
74
TypeError: fit() missing 1 required positional argument: 'X'
I've tried cutting out everything except my X and y arguments. That doesn't help. I've double checked to make sure that my X data does actually exist; it does. I've double checked that my X data is the right type; it is. I've googled the issue in every way that I can think to word it, but I can't find anyone who's gotten this same problem.
Basically, I have no idea what to do. Help.
Solution
rscv_model.fit
requires an X
(uppercase X) parameter, not lowercase.
Have a look at the docs.
Answered By - mcsoini
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.