import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt

# DATOS
y = [1, 1.4, 3.1, 5, 7, 9, 9.8, 10.1]
x = np.linspace(0, 1000, len(y))

# FUNCION
def funcion(x, a, b):
    return a*x + b

# OBTENCION PARAMETROS
parametros, parametros_cov = curve_fit(funcion, x, y)
r = np.corrcoef(y, funcion(x, parametros[0], parametros[1]))[0,1]

# REPRESENTACION
plt.scatter(x, y)
plt.plot(x, funcion(x, parametros[0], parametros[1]))
plt.show()

for i in range(len(parametros)):
    print(f"{parametros[i]}")
print(f"\nr = {r}")

# PARAMETROS INICIALEEES!!!