import pandas as pd import matplotlib.pyplot as plt import numpy as np donnees = pd.read_csv('http://louismerlin.fr/Enseignement/2223/TP/tp2_data.csv', sep =';') # print(donnees.head()) table1=donnees[['Année', 'taux fertilité j. femmes', 'femmes scol. sec.']] table1=table1.rename(columns={'taux fertilité j. femmes': 'TF', 'femmes scol. sec.':'FSS'}) # print(table1.mean()) # print(table1.std()) table1=table1.dropna() X = table1['FSS'] Y = table1['TF'] ## Dessin du nuage de points. # plt.grid() #plt.plot(X,Y,'k+') # plt.show() ## Droite de régression. # a = X.cov(Y) / ((X.std())**2) # b = Y.mean()-a*X.mean() # t=np.arange(51,67,0.01) # plt.grid() # plt.plot(X,Y,'k+') # plt.plot(t,a*t+b) # plt.show() ## Exercice 1 # table2=donnees[['Année', 'conso élec per capita', 'esperance vie']] # table2=table2.dropna() # A = table2['conso élec per capita'] # B = table2['esperance vie'] # plt.plot(A,B,'k+') # plt.show() # a = A.cov(B) / ((A.std())**2) # b = B.mean()-a*A.mean() # t=np.arange(2100,3300,1) # plt.plot(A,B,'k+') # plt.plot(t,a*t+b) # plt.show() ## Regression avec transformation # data2=pd.read_csv('https://louismerlin.fr/Enseignement/2223/TP/tp2_nor.csv', sep=';') # data2=data2.dropna() # X=data2['PIB per capita'] # Y=data2['Pop urbaine %'] # plt.grid() # plt.plot(X,Y, '.') # nuage de points # plt.show() # Xlog = np.log(X) # plt.plot(Xlog,Y,'.') # plt.show() # rho = Xlog.cov(Y) /(Xlog.std()*Y.std()) # print(rho) # a = Xlog.cov(Y)/((Xlog.std())**2) # b = Y.mean()-a*Xlog.mean() # t=np.arange(100,100000,10) # plt.plot(X,Y,'.') # plt.plot(t,a*(np.log(t))+b) # plt.show()