使用Keras进行深度学习的介绍:’X_train’未定义?

我正在尝试通过Keras更好地理解深度学习。我已经安装了Python、pip、TensorFlow和Jupyter Notebook来运行这个程序,但是根据来自towardsdatascience.com的“使用Keras进行深度学习的介绍”中的以下示例,我已经遇到了一个错误。如果这看起来很明显,请原谅我,这是我第一次做这种事情,当你第一次运行的示例中就出现了错误时,很难判断问题所在。

给出的第一块代码是:

from keras.datasets import mnist(x_train, y_train), (x_test, y_test) = mnist.load_data()

它声明使用TensorFlow后端。给出的第二块代码是:

x_train = x_train.astype('float32')x_test = x_test.astype('float32')x_train /= 255x_test /= 255x_train = X_train.reshape(X_train.shape[0], 28, 28, 1)x_test = X_test.reshape(X_test.shape[0], 28, 28, 1)

这会引发以下错误:

---------------------------------------------------------------------------NameError                                 Traceback (most recent call last)<ipython-input-2-e2db9b91827f> in <module>      4 x_test /= 255      5 ----> 6 x_train = X_train.reshape(X_train.shape[0], 28, 28, 1)      7 x_test = X_test.reshape(X_test.shape[0], 28, 28, 1)NameError: name 'X_train' is not defined

这是这两部分的截图: enter image description here

然而,我不明白在这种情况下x_train怎么会未定义,因为显然有一行代码是“x_train = x_train.astype(‘float32’)”


回答:

实际上,这只是示例中的大小写问题。x_test和x_train都被更改为

x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)

非常感谢oneturkmen指出这一点。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注