# -*- coding: utf-8 -*-
# Created on Wed May 28 15:15:15 2025
# @author: mhebding

import numpy as np
from scipy.stats import linregress

# Donnees
x = np.array([0,2.5,5,7.5,10]) 
y = np.array([2.2,7.7,12.4,17.7,21.1])

# Regression lineaire par linregress
(a,b,r,_,_) = linregress(x,y)
a,b,R = a,b, r**2
modele = a*x+b

# Regression lineaire par polyfit
droite_regression = np.polyfit(x,y,1) 
a2,b2 = droite_regression[0], droite_regression[1]
x2 = np.linspace(min(x), max(x), 100)
modele2 = a2*x2+b2

print("Modele : y = ax + b")
print("Par linregress :\n a = {}\n b = {}\n R = {}".format(a,b,R))
print("Par polyfit :\n a = {}\n b = {}".format(a2,b2))

import matplotlib.pyplot as plt
plt.scatter(x,y)
plt.plot(x,modele)
#plt.plot(x2,modele2)
plt.show()



