I have a dataframe like this:
data = pd.DataFrame({ 'l': [1, 2, 3, 4, 5], 'F': [2, 3, 4, 5, 6], })
- I have calculated (coulmn l - coulmn F)^2 and put result in new column for each row 2)Then I have calculated the average of that column, for example the averagre is x.
Now I want to have a column called coefficient and select the coefficients so that the average of the following formula (y) is less than the previous average, with the same procedure for x: (coulmn l - coefficient*coulmn F)^2
goal: y<x question: how to identify coefficients?
here is my code and it seems correct but does not work:
x = np.mean((data['l'] - data['F'])**2)
while True:
coefficients = np.random.uniform(0, 5, size=len(data))
result_data['coefficients'] = coefficients
result_data['estimated_squared_diff'] = (data['l'] - coefficients * data['F'])**2
y = np.mean(result_data['estimated_squared_diff'])
if y < x:
break
print(result_data['coefficients'])