0

我一直在使用这个模型和二进制数据来预测本指南中可能发生的事情。

import tensorflow as tf
from tensorflow import keras
import numpy  as np
import pandas as pd



model = keras.Sequential()

input_layer = keras.layers.Dense(3, input_shape=[3], activation='tanh')
model.add(input_layer)

output_layer = keras.layers.Dense(1, activation='sigmoid')
model.add(output_layer)

gd = tf.train.GradientDescentOptimizer(0.01)

model.compile(optimizer=gd, loss='mse')

sess = tf.Session()  #NEW LINE

training_x = np.array([[1, 1, 0], [1, 1, 1], [0, 1, 0], [-1, 1, 0], [-1, 0, 0], [-1, 0, 1],[0, 0, 1], [1, 1, 0], [1, 0, 0], [-1, 0, 0], [1, 0, 1], [0, 1, 1], [0, 0, 0], [-1, 1, 1]])
training_y = np.array([[0], [0], [1], [1], [1], [0], [1],[0], [1], [1], [1], [1], [1], [0]])



init_op = tf.initializers.global_variables()


sess.run(init_op)  #NEW LINE

model.fit(training_x, training_y, epochs=1000, steps_per_epoch = 10)


text_x = np.array([[1, 0, 0]])
test_y = model.predict(text_x, verbose=0, steps=1)

print(test_y)

所有当前数据都是二进制的,模型与二进制一起工作,是否有任何模型或方法可以将非二进制数据转换product_sold为以下数据集中的二进制预测可能性?

数据集:

number_infants    cost_of_infants     estimated_cost_infants    product_sold
5                     1000               2000                         0
6                     8919               1222                         1
7                     10000              891                          1

product_sold
1 = yes
0 = no

编辑:

lst = df 前三列的数组

[[5,1000,2000],[6,8919,1222]] 

lst_1 = 只有第 4 列的数组

[[0,1,1]]


training_x = np.array(lst)
training_y = np.array(lst_1)
4

0 回答 0