我已经编写了这个机器学习算法的代码,但它返回给我一个奇怪的数组。我想输入 2 个数字,然后将这些数字分类为在 Y 中找到的类似结果,如何使用此模型进行预测?
import numpy as np # mutivariate clasification
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
X =np.array(
[[3, 7],
[3, 6],
[3, 7.2],
[6, 8],
[7, 7.5],
[7.9, 7.5]])
Y =np.array([1, 1, 1, 2, 3, 3])
model = Sequential([
Dense(units = 25, activation = "relu"),
Dense(units = 15, activation = "relu"),
Dense(units = 10, activation = "softmax"),])
from keras.losses import SparseCategoricalCrossentropy
model.compile(loss = SparseCategoricalCrossentropy())
model.fit(X, Y, epochs = 100)
我试过这段代码:
Xpred = [[3,7.8]]
prediction = model.predict(Xpred, verbose = 1)
print(prediction)
它返回:
[[3.4789115e-02 8.4235787e-01 7.6775238e-02 1.9370530e-02 1.0821970e-02
4.8491983e-03 4.7121649e-03 7.4993627e-04 2.9366722e-04 5.2804169e-03]]
我是堆栈和 ML 的新手,所以请告诉我如何改进,或者如果您有任何 ML 的阅读材料或资源可以分享!