Académique Documents
Professionnel Documents
Culture Documents
linéaire simple
df = pd.read_csv('C:/Users/pc/Downloads/dataset0.csv')
plt.plot(df['X'],df['Y'],'o')
df.head()
X Y
0 1714 2.40
1 1664 2.52
2 1760 2.54
3 1685 2.74
4 1693 2.83
Visualisation
#seaborn.regplot() :
#Cette méthode est utilisée pour tracer les données et un modèle de régression linéaire
#Syntax : seaborn.regplot( x, y, data=None,...)
#Paramètres :
#x, y : ce sont des variables d'entrée.
# S'il s'agit de chaînes de caractéres, celles-ci doivent correspondre aux noms de colonne dans "data".
#data : Il s'agit d'une base de données où chaque colonne est une variable et chaque ligne est une observation.
Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 3.29e+04. This might indicate that there are
strong multicollinearity or other numerical problems.
ypred = model.predict(df['X'])
print(ypred)
0 10.977501
1 12.604424
2 12.774782
3 13.106981
4 14.137650
5 14.810565
6 14.478367
7 13.532877
8 14.904263
9 15.662358
10 16.428970
11 17.706658
12 19.495422
13 16.940046
14 13.626575
15 14.648725
16 15.151282
17 16.088254
18 16.778205
19 15.236462
20 17.033743
21 17.204101
22 18.481789
dtype: float64
Régression multiple
X2 X3 X4 X1
0 165349.20 136897.80 471784.10 192261.83
1 162597.70 151377.59 443898.53 191792.06
2 153441.51 101145.55 407934.54 191050.39
3 144372.41 118671.85 383199.62 182901.99
4 142107.34 91391.77 366168.42 166187.94
Création du modèle
y=df['X1']
x=df[['X2','X3','X4']]
x=sm.add_constant(x)
# Create a fitted model
lm = sm.OLS(y,x).fit()
Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.4e+06. This might indicate that there are
strong multicollinearity or other numerical problems.
ypred = lm.predict(x)
print(ypred)
0 192521.252890
1 189156.768232
2 182147.279096
3 173696.700026
4 172139.514183
5 163580.780571
6 158114.096669
7 160021.363048
8 151741.699699
9 154884.684110
10 135509.016367
11 135573.712961
12 129138.054182
13 127487.991663
14 149548.646335
15 146235.159985
16 116915.405401
17 130192.447208
18 129014.226806
19 115635.216367
20 116639.669231
21 117319.451640
22 114706.981717
23 109996.615221
24 113362.966113
25 102237.725065
26 110600.575350
27 114408.071457
28 101660.026005
29 101794.983452
30 99452.372936
31 97687.856276
32 99001.328985
33 97915.007805
34 89039.273741
35 90511.599568
36 75286.174585
37 89619.537708
38 69697.430648
39 83729.011977
40 74815.953991
41 74802.556239
42 70620.411821
43 60167.039963
44 64611.354916
45 47650.649687
46 56166.206853
47 46490.588983
48 49171.388158
49 48215.134111
dtype: float64
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js