Hi, I am trying to run this piece of code. I am getting the error ‘AttributeError: ‘Sequential’ object has no attribute ‘compiled’’. I am using TensorFlow version 2.14.0, Keras version 2.14.0, and SciKeras version 0.13.0.
import numpy as np
import tensorflow as tf
from sklearn.model_selection import cross_val_score
from keras.models import Sequential
from scikeras.wrappers import KerasRegressor
from math import floor
from sklearn.metrics import make_scorer, mean_squared_error
from sklearn.model_selection import StratifiedKFold, KFold
from keras.callbacks import EarlyStopping, ModelCheckpoint
from keras.layers import Dense
score_acc = make_scorer(mean_squared_error)
X_train = np.random.randn(10,3)
y_train = np.random.randn(10,1)
def nn_cl_fun():
nn = Sequential()
nn.add(Dense(5, input_dim=3, activation=‘relu’))
nn.add(Dense(5, activation=‘relu’))
nn.add(Dense(1))
nn.compile(loss=‘mean_squared_error’, optimizer=‘Adam’, metrics=[‘mean_squared_error’])
return nn
es = EarlyStopping(monitor=‘mean_squared_error’, mode=‘max’, verbose=0, patience=20)
nn1 = KerasRegressor(model=nn_cl_fun, epochs=10, verbose=0)
kfold1 = KFold(n_splits=2, shuffle=True, random_state=123)
score = cross_val_score(nn1, X_train, y_train, scoring=score_acc, error_score=‘raise’, fit_params={‘callbacks’:[es]}).mean()