0

I am learning my data set with the following code.

import numpy as np
from keras.models import Sequential
from keras.layers import Dense

np.random.seed(5)
dataset = np.loadtxt('path to dataset', delimeter=',')

x_train=dataset[:700,0:3]
y_train=dataset[:700,3]
x_test=dataset[700:,0:3]
y_test=dataset[700:,3]

model =Sequential()
model.add(Dense(12, input_dim=3, activate='relu'))
model.add(Dense(8, activate='relu'))
model.add(Dense(1, activate='sigmoid'))

model.compile(loss='binary_crossentropy', optimizer = 'adam', metrics = ['acuuracy'])
model.fit(x_train,y_train,epochs = 100, batch_size =24)

score = model.evaluate(x_test,y_test)

The above learning data consists of three attributes and two classes.

I would like to use the learned model above to determine data that the class does not contain.

For example, the learning data is (1, 34, 23, 0).

And the data I put in the input is (3,56,33), so I want to classify the class

using the learned model with these property information.

I would be very grateful if you could give me a concrete method.

송준석
  • 991
  • 1
  • 16
  • 32
  • Are you asking about how to use `model.predict()` to [classify new data points?](https://stackoverflow.com/q/37891954/9374673) – Mihai Chelaru May 08 '18 at 17:57
  • I do not know the command, but if you put the data value you want to predict with the parameters of model.predict (), then you're right. – 송준석 May 08 '18 at 18:11

1 Answers1

1

You can use model.predict() function to determine the class of any new datapoint. As in your case, if you want to predict the class of (3,56,33), you can write this after fitting the model,

model.fit(x_train,y_train,epochs = 100, batch_size =24)
prediction_prob = model.predict(np.array([3,56,33]))

Since, you are using sigmoid activation in the final layer, your output will be a single probability value between 0 and 1. You can then threshold the prediction to get the final class value.

prediction_prob = model.predict(np.array([3,56,33]))
class_name = int(round(prediction_prob[0]))
print(class_name)

Remember, that model.predict() takes a numpy array as input and outputs another numpy array of predictions.