Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Missing Positional Argument X

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

---------------------------------------------------------------------------
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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading