no way to compare when less than two revisions
Différences
Ci-dessous, les différences entre deux révisions de la page.
— | teaching:progappchim:regression_lineaire_2013 [2013/11/28 13:38] (Version actuelle) – créée villersd | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Régression linéaire ====== | ||
+ | Entrée de couples, calcul et affichage de la [[http:// | ||
+ | <sxh python; title : fit_linear.py> | ||
+ | # | ||
+ | # -*- coding: utf-8 -*- | ||
+ | # version un peu aménagée du travail de BD et EH, ba2 chimie 2012-2013 | ||
+ | |||
+ | import matplotlib.pyplot as plt | ||
+ | import pylab | ||
+ | import numpy | ||
+ | |||
+ | def droite_moindre_carre(x): | ||
+ | return a * x + b | ||
+ | |||
+ | tabx = [] | ||
+ | taby = [] | ||
+ | # Avoir le jeu de data | ||
+ | |||
+ | while True: | ||
+ | x = raw_input(" | ||
+ | y = raw_input(" | ||
+ | tabx.append(float(x)) | ||
+ | taby.append(float(y)) | ||
+ | another = raw_input(" | ||
+ | if another != " | ||
+ | break | ||
+ | # le remplir tant que l' | ||
+ | |||
+ | temp_min = 0.1 | ||
+ | temp_max = 20 | ||
+ | #axes horizontaux | ||
+ | |||
+ | a,b = pylab.polyfit(tabx, | ||
+ | # calcul du moindre carre | ||
+ | |||
+ | x_moindre_carre = numpy.linspace(min(tabx), | ||
+ | # | ||
+ | y_moindre_carre = map(droite_moindre_carre, | ||
+ | # calcul des valeurs de la courbe de moidnres carrés | ||
+ | # map => Utilise une fonction sur chaque element d'une liste | ||
+ | |||
+ | plt.axis([temp_min, | ||
+ | plt.plot(tabx, | ||
+ | # o => point, r => red | ||
+ | plt.plot(x_moindre_carre, | ||
+ | # b = blue, pas de o => line | ||
+ | plt.show() | ||
+ | # trace le graphique | ||
+ | </ |