Created
May 8, 2024 12:42
-
-
Save dolphin2410/c9707c58425a9bbad97c2aa726b8ec5d 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
from sklearn.linear_model import LinearRegression | |
import matplotlib.pyplot as plt | |
import numpy as np | |
data_time = [9.13E-02, 1.08E-01, 1.25E-01, 1.41E-01, 1.58E-01, 1.75E-01, 1.91E-01, 2.08E-01] | |
data_y = [1.50E-03, -4.40E-02, -9.14E-02, -1.44E-01, -2.00E-01, -2.63E-01, -3.24E-01, -3.92E-01] | |
regression = LinearRegression() | |
regression.fit(np.array(list(map(lambda x: [x**2, x], data_time))).reshape(-1, 2), np.array(data_y).reshape(-1, 1)) | |
a = regression.coef_[0][0] | |
b = regression.coef_[0][1] | |
c = regression.intercept_[0] | |
print([a,b,c]) | |
plt.title("y") | |
t_list = np.linspace(data_time[0], data_time[7], 10) | |
plt.plot(t_list, sum([item[0] * t_list**item[1] for item in [[c, 0], [b, 1], [a, 2]]])) | |
plt.scatter(data_time, data_y, marker="^", c="#000000") | |
plt.xlabel("t") | |
plt.ylabel("y") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment