Python Forum
Invalid syntax error(Predict Ethereum Price)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid syntax error(Predict Ethereum Price)
#1
Exclamation 
Good morning to the community Smile. I am using google colaboratory.
I would like to forecast the price of Ethereum.
But the console shows me the error: SyntaxError: invalid syntax about this line:
x_train, y_train = np.array(x_train), np.array(y_train)

Please find my code below:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import pandas_datareader as web
import datetime as dt
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.layers import Dense, Dropout, LSTM
from tensorflow.keras.models import Sequential

crypto_currency = 'ETH'
against_currency = 'USD'

start = dt.datetime (2015,6,15)
end  = dt.datetime.now()

data = web.DataReader(f'{crypto_currency}-{against_currency}', 'yahoo', start, end)

#Prepare Data
scaler = MinMaxScaler(feature_range(0,1))
scaled_data = scaler.fit_transform(data['Close'].values.reshape(-1,1))

prediction_days = 60

x_train, y_train = [], []

for x in range(prediction_days, len(scaled_data)):
  x_train.append(scaled_data[x-prediction_days:x, 0])
  y_train.append(scaled_data[x, 0]
            
x_train, y_train = np.array(x_train), np.array(y_train)
x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))

#Create neural network

model = Sequential()

model.add(LSTM(units=50, return_sequences=True, input_shape=(x_train.shape[1], 1)))
model.add(Dropout(0.2))
model.add(LSTM(units=50, return_sequences=True)
model.add(Dropout(0.2))
model.add(LSTM(units=50))
model.add(Dropout(0.2))
model.add(Dense(units=1)

model.compile(optimizer='adam', loss='mean_squared_error')
model.fit(x_train, y_train, epochs=25, batch_size=32 )


#Testing the model
test_start = dt.datetime(2020,1,1)
test_end = dt.datetime.now()

test_data = web.DataReader(f'{crypto_currency}-{against_currency}', 'yahoo', start, end)
actual_prices = test_data['Close'].values

total_dataset = pd.concat((data['Close'], test_data['Close']), axis = 0)

model_inputs = total_dataset[len(total_dataset)-len(test_data) - prediction_days:].values
model_inputs = model_inputs.reshape(-1,1)
model_inputs = scaler.fit_transform(model_inputs)

x_test = []

for x in range(prediction_days, len(model_inputs)):
  x_test.append(model_inputs[x-prediction_days:x,0])

x_test = np.array(x_test)
x_test = np.reshape(x_test, (x_test.reshape[0], x_test.shape[1], 1))

prediction_prices = model.predict(x_test)
prediction_prices = scaler.inverse_transform(prediction_prices)

plt.plot(actual_prices, color = 'black', label='Actual Prices')
plt.plot(prediction_prices, color='green', label ='Predicted Prices')
plt.title(f'{crypto_currency}price_prediction')
plt.xlabel('Time')
plt.ylabel('Price')
plt.legend(loc='upper left')
plt.show()
Thank you for your help.
Reply
#2
Close bracket ) missing from the end of line 28
Reply
#3
(Sep-24-2021, 12:34 PM)Yoriz Wrote: Close bracket ) missing from the end of line 28

Thank you Yoriz.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Finding the price based on industry and number of transactions chandramouliarun 1 1,058 Jun-04-2024, 06:57 PM
Last Post: marythodge4
  Cant install Ethereum 2.3.2 Rubenvdw 1 175 May-29-2024, 08:39 PM
Last Post: snippsat
  is this really a syntax error? Skaperen 4 363 May-25-2024, 07:31 AM
Last Post: snippsat
  World Clock syntax error OscarBoots 1 322 May-03-2024, 05:20 AM
Last Post: snippsat
  Syntax error for "root = Tk()" dlwaddel 15 1,630 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 554 Jan-19-2024, 01:20 PM
Last Post: rob101
  error: invalid command 'egg_info' TimTu 0 1,058 Jul-27-2023, 07:30 AM
Last Post: TimTu
  Syntax error while executing the Python code in Linux DivAsh 8 1,959 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,424 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  print(data) is suddenly invalid syntax db042190 6 1,343 Jun-14-2023, 02:55 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020