The code below throws the error 'numpy.float64' object is not callable at last_mae = mae(val_scaled_price_client, cv_model). Nevertheless the mae function with the same parameters works just fine when used outside the loop.
loss_history = [1000.00]
for i in range(10000):
# train
iterations = 10
train_auto_encoder(train_latent_customers=train_latentvars,
train_product_customers=train_scaled_price_client,
auto_encoder=auto_model,
iters=iterations,
batch_size=128,
display_step=20)
cv_model = auto_model.predict([val_latentvars, val_scaled_price_client_corrupted])
last_mae = mae(val_scaled_price_client, cv_model)
loss_history.append(last_mae)
if loss_history[-1] < loss_history[-2]:
iterations += 10
else:
break
I declared a function mae in previous cells as follow
# define function to calculate MAE between true and reconstructed values
def mae(y_true, y_pred):
# get non-zero positions
cond = np.not_equal(y_true, 0)
# get number of non-zero elements
num_non_zero = np.sum(cond)
# initialize zer matrix
zero_matrix = np.zeros(shape=y_true.shape)
# replace
predictions_corrected = np.where(cond, y_pred, zero_matrix)
# get rmse
mae = np.sum(np.abs(y_true - predictions_corrected)) / num_non_zero
# return
return(mae)
maeis a number, you use it as a function. Most probably you unintentionally overwrote you function definition ofmaewith a number.maeinmae = np.sum(np.abs(y_true - predictions_corrected)) / num_non_zero. Change this toreturn np.sum(np.abs(y_true - predictions_corrected)) / num_non_zeroand everything will be OK :)