为什么我会遇到函数调用堆栈:train_function 错误

我在尝试训练一个简单的神经网络时遇到了这个错误,我尝试了一些其他类似问题的答案,但没有效果。我想对 TYPE=0 和 TYPE=1 进行分类。链接末尾是我训练数据集的一个示例。

tensorflow.python.framework.errors_impl.UnimplementedError:  Cast string to float is not supported     [[node sequential/Cast (defined at /Users/Administrator/Desktop/New folder/ne.py:31) ]] [Op:__inference_train_function_587]Function call stack:train_function

这是我的神经网络代码

 model = keras.Sequential([    keras.layers.Dense(1560, input_shape=(6,), activation='relu'),    keras.layers.Dense(1, activation='sigmoid')])    model.compile(optimizer='adam', loss=keras.losses.BinaryCrossentropy(from_logits=True), metrics=['accuracy'])        model.fit(X_train, y_train, batch_size=1,epochs=5)

这是我的数据集示例,以Excel格式提供,希望对你有帮助

        MPF      MF    PSD   F95    BMI  PARITY TYPEe001_1  0.0048  0.005   6   0.008   27.6    2   1e001_2  0.0077  0.005   6   0.008   27.6    2   1e001_3  0.004   0.005   6   0.008   27.6    2   1e001_4  0.0024  0.004   6   0.008   27.6    2   1e001_5  0.0025  0.004   6   0.008   27.6    2   1e001_6  0.0034  0.004   6   0.008   27.6    2   1e003_1o 7.52E-04    5.45E-04    6   0.001089918 34  0   0e003_1o 5.31E-04    5.45E-04    6   0.001089918 34  0   0e003_1o 6.49E-04    5.45E-04    6   0.001089918 34  0   0e003_1o 9.98E-04    5.45E-04    6   0.001089918 34  0   0e003_1o 0.001258642 5.45E-04    6   0.001089918 34  0   0e003_1o 5.76E-04    5.45E-04    6   0.001089918 34  0   0

回答:

你没有提供如何加载csv文件的信息,所以很难确切知道发生了什么。

我稍微修改了你的代码,并使用pandas加载数据,结果它工作了。

这是代码

import tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import layersfrom tensorflow.keras.layers.experimental import preprocessingfrom matplotlib import pyplot as pltimport pandas as pdimport numpy as npimport datetimeexample_ds = pd.read_csv(    "Example.csv")print(example_ds)y_train = example_ds.loc[:, 'TYPE']x_train = example_ds.loc[:, 'MPF': 'PARITY']model = keras.Sequential([    keras.layers.Dense(1560, input_shape=(6,), activation='relu'),    keras.layers.Dense(1, activation='sigmoid')])model.compile(optimizer='adam', loss=keras.losses.BinaryCrossentropy(from_logits=True), metrics=['accuracy'])    model.fit(x_train, y_train, batch_size=1,epochs=5)

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中创建了一个多类分类项目。该项目可以对…

发表回复

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