Python语法错误:语法无效。不知道为什么吗?

时间:2019-04-25 00:21:40

标签: python dataset

全方位的工作:我下载了Spyder,并能够使用它来完成任务。仍然不确定为什么Anaconda Prompt会给我错误。

我正在围绕AI分配完成一个实验教程,当我输入用于训练数据集的代码时,出现了我无法解决的语法错误。 这是为了使代码达到目的而提供的注释;

由于LSTM存储长期内存状态,因此我们创建了一个具有60个时间步长和1个输出的数据结构。 因此,对于训练集的每个元素,我们都有60个先前的训练集元素。

import numpy as np
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM, Dropout, GRU, Bidirectional
from keras.optimizers import SGD
import math
from sklearn.metrics import mean_squared_error

def plot_predictions(test,predicted):
    plt.plot(test, color='red',label='Real IBM Stock Price')
    plt.plot(predicted, color='blue',label='Predicted IBM Stock Price')
    plt.title('IBM Stock Price Prediction')
    plt.xlabel('Time')
    plt.ylabel('IBM Stock Price')
    plt.legend()
    plt.show()

def return_rmse(test,predicted):
    rmse = math.sqrt(mean_squared_error(test, predicted))
    print("The root mean squared error is {}.".format(rmse))

dataset = pd.read_csv('stock-20050101-to-20171231/IBM_2006-01-01_to_2018-01-01.csv', index_col='Date', parse_dates=['Date'])
dataset.head()

training_set = dataset[:'2016'].iloc[:,1:2].values
test_set = dataset['2017':].iloc[:,1:2].values

dataset["High"][:'2016'].plot(figsize=(16,4),legend=True)
dataset["High"]['2017':].plot(figsize=(16,4),legend=True)
plt.legend(['Training set (Before 2017)','Test set (2017 and beyond)'])
plt.title('IBM stock price')
plt.show()

sc = MinMaxScaler(feature_range=(0,1))
training_set_scaled = sc.fit_transform(training_set)

X_train = []
y_train = []
for i in range(60,2769):
    X_train.append(training_set_scaled[i-60:i,0])
    y_train.append(training_set_scaled[i,0])
X_train, y_train = np.array(X_train), np.array(y_train)`

我得到的输出是:

File "<stdin>", line 4
X_train, y_train = np.array(X_train), np.array(y_train)
      ^
SyntaxError: invalid syntax

0 个答案:

没有答案