I was trying to created a simple model, wrapped in keras wrapper. When I test it with simple input, I get the TypeError: object of type 'NoneType' has no len()
. I was using scikeras
wrapper.
Also, the error is because of the wrapper, not exatly sure why though, when I remove the wrapper the above code works fine.
The input features are coming from pipelines, after one hot encoding and hence prefer to avoid specifying the input size if there is a chance. The model is working if not wrapped in the regressor, but not sure why it is not working in the wrapper.
Can someone please explain how to fix this ?
from tensorflow.keras.models import Sequential
from scikeras.wrappers import KerasRegressor
def build_net(net_loss = 'mean_squared_error', net_optimizer='adam',):
model = Sequential()
model.add(Dense(25, activation='relu'))
model.add(Dense(9, activation='relu'))
model.add(Dense(4, activation='relu'))
model.add(Dense(1, activation='linear'))
model.compile(loss=net_loss, optimizer=net_optimizer, metrics=['root_mean_squared_error','mean_absolute_error'])
return model
net = KerasRegressor(model=build_net, epochs = 5, verbose=0)
net.fit(np.random.randint(50, size=(2000, 4)), np.random.randint(1, size=2000))