I have a function. I need to minimize the MSE to 0.75 or less. I was able to get to 6 and don't know what to do next.
def print_points_ands_function1(sympy_function):
def function(x_): return float(sympy_function.subs(x, x_))
points_X = np.array([-2, -1, 0, 1, 2, 3, 3.5, 4, 4.5, 5])
points_Y = np.array([3, 1, -0.5, 1.2, 2.5, 0.8, -2, -3.5, -3, -5])
plt.xlim(-10, 10)
plt.ylim(-5, 5)
plt.scatter(points_X, points_Y, c='r')
x_range = np.linspace(plt.xlim()[0], plt.xlim()[1], num=100)
function_Y = [function(x_) for x_ in x_range]
plt.plot(x_range, function_Y, 'b')
plt.show()
MSE = sum([(points_Y[i] - function(points_X[i]))**2 for i in range(len(points_Y))]) / len(points_Y)
print(f'MSE = {MSE}')
f1 = 2 * x * sin(2 * x + 5) + 5 * sin(2 * x + 5) + 2
print(f1)
print_points_ands_function1(f1)
f1_1 = expand(f1.subs(x, x / 1.4))
print(f1_1)
print_points_ands_function1(f1_1)
f1_2 = expand(f1_1.subs(x, -x))
print(f1_2)
print_points_ands_function1(f1_2)
f1_3 = expand(f1_2.subs(x, x + 2.6))
print(f1_3)
print_points_ands_function1(f1_3)