为什么我的输出“ nan” nan&quort'keras模型预测
我正在尝试使AI试图预测质数序列的数字,但是我的模型输出“ [[NAN]]”。我的CSV文件的格式是这样的:
Prime,Prime的数量
,并且包含78498行遵循此模式。
我尝试查看模型,事实证明我的输入形状(无,1)
。
有人知道如何解决这个问题吗?
这是我的代码:
import pandas as pd
import tensorflow as tf
from tensorflow import keras
data = pd.read_csv('primes.csv')
data = np.array(data, dtype=float)
data = data.T
numbers = np.array(data[0])
primes = np.array(data[1])
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')
model.fit(numbers, primes, epochs=10)
results = model.predict([1000000])
print(results)
model.save('model.h5')
我使用TensorFlow:2.8.0
I'm trying to make an AI attempting to predict numbers from prime number sequence, but my model outputs "[[nan]]". My csv file is formatted like this:
number of the prime, prime
and it contains 78498 lines following this pattern.
I tried looking into the model and it turns out I have input shape of (None, 1)
.
Does anyone know how to fix this?
here is my code:
import pandas as pd
import tensorflow as tf
from tensorflow import keras
data = pd.read_csv('primes.csv')
data = np.array(data, dtype=float)
data = data.T
numbers = np.array(data[0])
primes = np.array(data[1])
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')
model.fit(numbers, primes, epochs=10)
results = model.predict([1000000])
print(results)
model.save('model.h5')
I use tensorflow: 2.8.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个示例转换类,您可以
在这种情况下使用分类值
status_mapping
您可以将这些笔记本用于NAN值
https://www.kaggle.com/code/parulpandey/a-guide/a-guide-to to and-missing-missing-missing-values-values-values-values-values-values-values-values-values-values-values-values- python
This is a sample transformation class you can use
The categorical value in this case is
status_mapping
You can use these notebook for NAN values
https://www.kaggle.com/code/parulpandey/a-guide-to-handling-missing-values-in-python