Least Square Method, Curve Fitting, Python, Residual, Data.
plt.ylabel('Residuals') plt.show() # Calculate R-squared ss_total1 = np.sum((ydata1 - np.mean(ydata1))**2) ss_residual1 = np.sum(residuals1**2) r_squared1 = 1 - (ss_residual1 / ss_total1) print(f"R-squared: {r_squared1}") # Print the values of 'a' and 'k' afit, bfit, cfit = popt print("Fitted value