Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help fixing the error in the Kera model section . The rest of the code is for reference. The error stated NameError: name
I need help fixing the error in the Kera model section. The rest of the code is for reference. The error stated
NameError: name 'np' is not definedIn [ ]: print('Input data size :', X. shape) print('Output data size :', Y. shape) print('Label names:', face_data.target_names) In []:Y[:5] In [ ]: for i in range(5): print(f'Class {i} has {(Y==i)sum()} samples. ') In [ ]: import matplotlib.pyplot as plt fig, ax=plt. subplots (3,4) for i, axi in enumerate(ax.flat): axi.imshow (face_data.images [i], cmap='bone') axi. set (xticks =[], yticks =[], xlabel=face_data.target_names[face_data.target [i]]) plt. show ( ) In [ ] : from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(face_data.data, face_data.target, from keras.models import Sequential from keras. layers import Dense def build_model(hidden_units=64, optimizer='adam', learning_rate=0.001): model = Sequential() model.add(Dense(hidden_units, activation='relu', input_shape=(X_train_scaled.shape[1], ))) model.add(Dense(hidden_units, activation='relu')) model.add(Dense(len(np.unique(y_train)), activation='softmax')) if optimizer == 'adam': opt = keras.optimizers.Adam(learning_rate=learning_rate) opt = keras.optimizers.SGD(learning_rate=learning_rate) model. compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy']) return model We will then use GridSearchCV to tune the hyperparameters and find the best estimator
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started