How To Predict Doge Coin Price Using Machine Learning and Python
How To Predict Doge Coin Price Using Machine Learning and Python
Manpreet Singh
Awesome! Now we must create some new data frames that will
help us hold the data for us, let’s go line by line (almost), let’s go
ahead and start by creating these variables / empty dataframes:
T = 10
D = 1
X = []
Y = []
Awesome! now we are going to use “T” as our past variable, aka
how many days we’re going back in order to predict the future.
Next up, we’re going to use a for loop to go through our series
data, so let’s start off by declaring our for loop, we are going to use
the following line:
for t in range(len(series) — T):
Now we do the same thing but instead of slicing the dataset we’re
going to be just using it as a counter within the series dataset, we
then append that same data to the Y data frame we created earlier.
y = series[t+T]
Y.append(y)
Finally, we want to reshape our data frame, this will basically give
a new shape to our data frame without changing any of the data in
this data frame, we will then create an array for the “Y” data frame
as well, finally we will get the length of the “X” array and store it in
a new variable called “N”.
X = np.array(X).reshape(-1, T)
Y = np.array(Y)
N = len(X)
print(“X.shape”, X.shape, “Y.shape”, Y.shape)
Next up we’re going to have to split up our data to a train and test
set. We do so by creating the Xtrain & Train variables, we then use
the “X” and “N” variables we used before to fill those variables
with data, we essentially do the same thing with our “Xtest” and
“Ytest” variables with the other half of the data for our test set:
Xtrain, Ytrain = X[:-N//2], Y[:-N//2]
Xtest, Ytest = X[-N//2:], Y[-N//2:]
Awesome! Next up let’s go ahead and setup our model, we’re going
to create a “model” variable that holds our “BaselineModel” class,
we’re going to create some new variables to pass our train and
testing data frames, we do so by using the following code:
model = BaselineModel()
Ptrain = model.predict(Xtrain)
Ptest = model.predict(Xtest)
Great! Now we’re going to go ahead and reshape our arrays once
more and store them into another variable as well as create the 1D
array with Numpy:
Ytrain2 = scaler.inverse_transform(Ytrain.reshape(-1, 1)).flatten()
Ytest2 = scaler.inverse_transform(Ytest.reshape(-1, 1)).flatten()
Ptrain2 = scaler.inverse_transform(Ptrain.reshape(-1, 1)).flatten()
Ptest2 = scaler.inverse_transform(Ptest.reshape(-1, 1)).flatten()
Almost Done! Now we’re going to go ahead and send our data to
pretty much be forecasted, the future data will be appended into
our “forecast” variable, then our data will be plotted using the
package matplotlib! This is the code to do that:
# right forecast
forecast = []
input_ = Xtest[0]
while len(forecast) < len(Ytest):
f = model.predict(input_.reshape(1, T))[0]
forecast.append(f)
# make a new input with the latest forecast
input_ = np.roll(input_, -1)
input_[-1] = f
plt.plot(Ytest, label=’target’)
plt.plot(forecast, label=’prediction’)
plt.legend()
plt.title(“Right forecast”)
plt.show()
As Always
As always, if you have any suggestions, thoughts or just want to
connect, feel free to contact / follow me on Twitter! Also, below is
a link to some of my favorite resources for learning programming,
Python, R, Data Science, etc.
My Recommendations
Here are some of my favorite courses, books and so much more. Most
of these are affiliate links which help me create…
sites.google.com
17
17
Cryptocurrency
Python
Machine Learning
Artificial Intelligence
Coding
Apr 23
Let’s begin!
Programiz C Course
Apr 23
First off