# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Tesla Stock Price Prediction with Machine Learning

# Predicting Stock prices is a great use case of machine learning both for financial and time series analysis. Tesla has been in the eyes of the world for a long time now as governments of so many countries all over the world are supporting the vision of Tesla. So in this article, I will take you through a tutorial on how to use the Facebook Prophet model for the task of stock price prediction of Tesla.
#
# The dataset that I will be using here has been downloaded from yahoo finance. To download this dataset simply visit yahoo finance and search for TSLA. You will see a dashboard as shown in the image below

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

from fbprophet import Prophet

import os

os.chdir("E:\\PYTHON NOTES\\projects\\100 data science projeect\\tesla stoke price")

data=pd.read_csv("TSLA.csv")

data

# Before moving forward let’s visualize the “Close” column in the dataset which represents close prices of each day:

close=data["Close"]
ax=close.plot(title="Tesla")
ax.set_xlabel("Date")
ax.set_ylabel("close")

# We only need two columns from this dataset (Date and Close), so let’s create a new DataFrame with only these two columns:

data["Date"]=pd.to_datetime(data["Date"],infer_datetime_format="True")

data=data[["Date","Close"]]

data

# As we are using the Facebook prophet model here for predicting the stock prices of Tesla so we need to rename the columns

data=data.rename(columns={"Date":"ds","Close":"y"})

data

model=Prophet()

model.fit(data)

future=model.make_future_dataframe(periods=365)


forcast=model.predict(future)

forcast[["ds","yhat","yhat_lower","yhat_upper"]].tail()

graph=model.plot(forcast,xlabel="Date",ylabel="price")

# # Conclusion

#
# It seems like Tesla’s stock prices will decrease in the coming future if they don’t come up with a new idea of representing their vision.



StarcoderdataJupyterScriptsDedupFiltered