import os
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from sklearn.linear_model import LinearRegression
sns.set()
os.chdir(r'D:\projects\wordpress\ex57')
os.getcwd()
rng = np.random.RandomState(1)
x = 10 * rng.rand(50)
y = 2 * x - 5 + rng.randn(50)
plt.scatter(x, y)
model = LinearRegression(fit_intercept=True)
model.fit(x[:, np.newaxis], y)
xfit = np.linspace(0, 10, 1000)
yfit = model.predict(xfit[:, np.newaxis])
plt.scatter(x,y,color='blue')
plt.plot(xfit,yfit,color='red')
print("Model slope: ", model.coef_[0])
print("Model intercept:", model.intercept_)
plt.savefig("example57.png", dpi=100)
plt.show()
plt.close()

example66

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading