# https://www.youtube.com/watch?v=7RgoHTMbp4A
# Draw Scatter Diagram & Regression Line
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LinearRegression
import random
reg = LinearRegression()
x_values, y_values = [], []
plt.xlim(0, 100)
plt.ylim(0, 100)
for i in range(95):
plt.clf()
x_values.append(random.randint(0, 100))
y_values.append(random.randint(0, 100))
x = np.array(x_values)
x = x.reshape(-1, 1)
y = np.array(y_values)
y = y.reshape(-1, 1)
if i % 5 == 0 or i == 94:
reg.fit(x, y)
plt.scatter(x_values, y_values, color='brown')
plt.plot(list(range(100)), reg.predict(np.array([x for x in range(100)]).reshape(-1, 1)))
plt.pause(0.0001)
plt.show()
# Draw histogram
import matplotlib.pyplot as plt
import random
values = [0] * 50
plt.xlim(0, 50)
plt.ylim(0, 100)
for i in range(50):
values[i] = random.randint(0, 100)
plt.bar(list(range(50)), values)
plt.pause(0.0001)
plt.show()
No comments:
Post a Comment