Ihr könntet mit sklearn die Lineare Regressionsrate berechnen und mit matplotlib es reinzeichnen.
from sklearn import linear_model
import numpy as np
import matplotlib.pyplot as plt
x= np.array( [145, 130, 130, 120, 120, 140, 140, 120, 172, 150, 140, 130, 130, 110, 150]).reshape(-1, 1)
y= [233, 250, 204, 236, 354, 192, 294, 263, 199, 168, 239, 275, 266, 211, 283]
lm = linear_model.LinearRegression()
lm.fit(x, y)
plt.scatter(x, y, color = "r",marker = "o", s = 30) #https://matplotlib.org/stable/api/markers_api.html#module-matplotlib.markers
y_pred = lm.predict(x)
plt.plot(x, y_pred, color = "k")
plt.ylabel("Cholesterin")
plt.xlabel("puls")
plt.show()
Alternativ könnte man es auch so machen:
import matplotlib.pyplot as plt
from scipy import stats
x= [145, 130, 130, 120, 120, 140, 140, 120, 172, 150, 140, 130, 130, 110, 150]
y= [233, 250, 204, 236, 354, 192, 294, 263, 199, 168, 239, 275, 266, 211, 283]
slope, intercept, r, p, std_err = stats.linregress(x, y)
def myfunc(x):
return slope * x + intercept
mymodel = list(map(myfunc, x))
plt.scatter(x, y, color = "r",marker = "o", s = 30)
plt.plot(x, mymodel, color = "k")
plt.ylabel("Cholesterin")
plt.xlabel("puls")
plt.show()