Created
June 5, 2019 17:10
-
-
Save dkreider/595266b4cebed1f64d0d6f3bb7895c64 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
# -*- coding: utf-8 -*- | |
"""Stock Prediction.ipynb | |
Automatically generated by Colaboratory. | |
Original file is located at | |
https://colab.research.google.com/drive/1Q2USewP4-0keoFCGLggC3-QCQf95vGQH | |
""" | |
!kaggle datasets download -d rpaguirre/tesla-stock-price | |
!unzip tesla-stock-price.zip | |
!mv "Tesla.csv - Tesla.csv.csv" "Tesla.csv" | |
from sklearn.model_selection import train_test_split | |
from sklearn.linear_model import LinearRegression | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import numpy as np | |
# Load data and display it in a simple plot | |
data = pd.read_csv('Tesla.csv', delimiter=',') | |
data.head() | |
prices = data['Close'].tolist() | |
dates = data.index.tolist() | |
plt.plot(dates, prices, color='blue', label='Actual Price', linewidth=1) | |
plt.title("Tesla Stock Prices (2010 - 2017)") | |
plt.xlabel("Date Integer") | |
plt.show() | |
# Prepare and train | |
X_data = np.reshape(dates, (len(dates), 1)) | |
Y_data = np.reshape(prices, (len(prices), 1)) | |
X_train, X_test, y_train, y_test = train_test_split(X_data, Y_data, test_size=0.25) | |
regressor = LinearRegression() | |
regressor.fit(X_train, y_train) | |
# Plot data and prediction | |
plt.plot(dates, prices, color='blue', label='Stock History', linewidth=2) | |
plt.plot(X_test, regressor.predict(X_test), color='yellow', linewidth=2, label="Linear Regression Prediction") | |
plt.title("General Overview") | |
plt.legend() | |
plt.xlabel("Date Integer") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment