You are on page 1of 3

5/16/23, 1:31 PM Untitled0.

ipynb - Colaboratory

# importation des bibiothéques:


import numpy as np
import pandas as pd
import seaborn as sns
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

# importation du fichier exel:


data=pd.read_excel("/content/pb.xlsx")

# visualisatin de dataset:
data

Surface Connexions Efficacité Nombre optimal


obs
(m²) simultanées énergétique de cellules

Quartier
0 800 50 75 10
1

Quartier
1 1200 80 82 12
2

Quartier
2 950 60 68 9
3

Quartier
3 1100 75 77 11
4

Quartier
4 700 40 71 8
5

Quartier
5 850 55 85 10
6

Quartier
6 1000 65 74 9
7

Quartier
7 1300 90 78 12
8

Quartier
8 900 70 80 10
9

Quartier
9 1000 60 76 9
10

Quartier
10 850 45 72 8
11

Quartier
11 1100 85 83 13
12

Quartier
12 750 55 69 8
13

# definir des predicteurs et des featurs:


X=data[['Surface (m²)','Connexions simultanées','Efficacité énergétique']]
Y=data[['Nombre optimal de cellules']]

# implimentation du model et calcule du coeffficient:b0,b1,b2,b3


model =LinearRegression()
model.fit(X,Y)
Intercept =model.intercept_
coefficients=model.coef_
Score =model.score(X,Y)

print(Intercept,coefficients,Score)

[-2.96702724] [[-0.00032933 0.08673693 0.09919851]] 0.8663177999743497

print(Intercept,coefficients)

https://colab.research.google.com/drive/1KUY2IwOyobimlVFknQx3xt-m18Qq3o0J#printMode=true 1/3
5/16/23, 1:31 PM Untitled0.ipynb - Colaboratory

[-2.96702724] [[-0.00032933 0.08673693 0.09919851]]

#afficher les coefficient:


print(coefficients)

[[-0.00032933 0.08673693 0.09919851]]

# calcule les Y predicturs à partir du dataset:


Y_pred =model.predict(X)
Y_pred

array([[ 8.54624432],
[11.71101017],
[ 8.66982469],
[10.81426587],
[ 7.31501389],
[ 9.95544762],
[ 9.68223395],
[12.14865252],
[10.74404253],
[ 9.44694633],
[ 7.79849771],
[12.2768262 ],
[ 8.40120434],
[10.76446669],
[12.28078391],
[ 8.3478473 ],
[10.79384171],
[ 9.57907773],
[11.92587363],
[ 9.7978989 ]])

#nb de cellule en fonction de nb de cellule estimé:


plt.plot(Y,Y_pred ,'.')
plt.show

<function matplotlib.pyplot.show(close=None, block=None)>

#validation du model en testant pour un datatest et les resultat sont trés proche

appart=[1000,60,88]
estimation=np.sum(coefficients*appart)+Intercept
estimation

array([10.63732845])

# calcule de RSS:
residuals=Y-Y_pred

https://colab.research.google.com/drive/1KUY2IwOyobimlVFknQx3xt-m18Qq3o0J#printMode=true 2/3
5/16/23, 1:31 PM Untitled0.ipynb - Colaboratory
RSS=np.sum(residuals**2)

RSS

Nombre optimal de cellules 7.078472


dtype: float64

Colab paid products - Cancel contracts here

https://colab.research.google.com/drive/1KUY2IwOyobimlVFknQx3xt-m18Qq3o0J#printMode=true 3/3

You might also like