Last active
May 14, 2020 11:59
-
-
Save Nick3523/1f021296f2d25911ba1c435e780037d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
#Fonction dont le rôle est d'obtenir les paramètres de l'équation de la droite de régression linéaire. | |
def getParams(x, y) : | |
X = np.matrix([np.ones(len(x)), x]).T | |
Y = np.matrix(y).T | |
theta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(Y) | |
b, a = theta.item(0), theta.item(1) | |
return b,a | |
x1 = np.array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5]) | |
y1 = np.array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68]) | |
x2, x3 = x1, x1 | |
y2 = np.array([9.14, 8.14, 8.74, 8.77, 9.26, 8.1, 6.13, 3.1, 9.13, 7.26, 4.74]) | |
y3 = np.array([7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73]) | |
y4 = np.array([6.58, 5.76, 7.71, 8.84, 8.47, 7.04, 5.25, 12.5, 5.56, 7.91, 6.89]) | |
x4 = np.array([8, 8, 8, 8, 8, 8, 8, 19, 8, 8, 8]) | |
#Inutile d'obtenir les paramètres pour x2,y2, etc..Car les paramètres sont identiques | |
b, a = getParams(x1, y1) | |
XValues = [x1, x2, x3, x4] | |
YValues = [y1, y2, y3, y4] | |
# 4 subplots | |
f, ax = plt.subplots(2, 2, figsize=(25, 20)) | |
m = 0 | |
for i in range(2): | |
for j in range(2): | |
ax[i][j].scatter(XValues[m], YValues[m], c ='red', linewidths=7) | |
ax[i][j].plot(XValues[m], a * XValues[m] + b, c='#000000') | |
m = m + 1 | |
plt.savefig("Quartet", dpi=144) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment