import matplotlib.pyplot as plt
import numpy as np

# Mean Squared Error Loss
def mse_loss(y_true, y_pred):
    return (y_true - y_pred) ** 2

# Negative Log-Likelihood Loss
def nll_loss(y_true, y_pred):
    return - (y_true * np.log(y_pred) + (1 - y_true) * np.log(1 - y_pred))

# Predicted probabilities
y_hat = np.linspace(0, 1, 100)
true_label = 1

# Calculate loss values
mse_losses = mse_loss(true_label, y_hat)
nll_losses = nll_loss(true_label, y_hat)

# Plotting the losses
fig, ax = plt.subplots(1, 2, figsize=(15, 6))

# MSE Loss plot
ax[0].plot(y_hat, mse_losses, 'b', label='MSE Loss')
ax[0].set_title('Mean Squared Error Loss\\n(True label y=1)')
ax[0].set_xlabel('Predicted Probability (y_hat)')
ax[0].set_ylabel('Loss')
ax[0].legend()

# NLL Loss plot
ax[1].plot(y_hat, nll_losses, 'r', label='NLL Loss')
ax[1].set_title('Negative Log-Likelihood Loss\\n(True label y=1)')
ax[1].set_xlabel('Predicted Probability (y_hat)')
ax[1].set_ylabel('Loss')
ax[1].legend()

# Show the plots
plt.tight_layout()
plt.show()