Skip to content

Instantly share code, notes, and snippets.

@gibtang
Created June 13, 2020 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gibtang/62e854d6fb5976601193b089e8dc85d4 to your computer and use it in GitHub Desktop.
Save gibtang/62e854d6fb5976601193b089e8dc85d4 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
dataset = pd.read_csv('S_n_P - V-2.csv')
X = dataset.iloc[:, 1].values.reshape(-1, 1)
y = dataset.iloc[:, 12].values.reshape(-1, 1)
plt.scatter(X, y, color = 'red')
plt.title('S&P')
plt.xlabel('Day')
plt.ylabel('Price')
plt.grid(b=True, color='blue', alpha=0.6, linestyle='dashdot')
plt.show()
from sklearn.preprocessing import PolynomialFeatures
polynomial_reg = PolynomialFeatures(degree = 5)
X_polynomial = polynomial_reg.fit_transform(X)
lin_reg_2 = LinearRegression()
lin_reg_2.fit(X_polynomial, y)
plt.plot(X, lin_reg_2.predict(polynomial_reg.fit_transform(X)), color = 'grey')
plt.minorticks_on()
plt.grid(which='minor', linestyle=':', linewidth='0.5', color='black')
plt.grid(b=True, color='blue', alpha=0.6, linestyle='dashdot')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment