0
$\begingroup$

I am trying to build a recommender predicting products. The inputs are one-hot encoded product IDs, and so is the output. (0, 0, 1, 0) to (1, 0, 0, 0) There are 83 unique IDs in the first category and 32 in the second. I imagined that the model should easily learn these combinations because the dataset only contains product combination, which occur 10 times or more.

The problem is that the accuracy is not getting better than 25% at the test-data. I have tried to evaluate the predictions using the training-data, so the accuracy should be very high because the model is predicting already seen data. Am I wrong with this assumption?

Is it even possible to predict one-hot-vectors with that many categories?

Here is my code:

# Parameters
Batch_Size = 64
Learning_Rate = 0.001
Epochs = 100


def import_data(url):
    dataframe = pd.read_csv(url)
    return dataframe


def prepare_df(data):
    data['Shirts'] = data["Shirt"].astype('category').cat.codes
    data['Pants'] = data['Pant'].astype('category').cat.codes

    return data


def create_model():
    my_model = Sequential()
    my_model.add(Dense(83, input_dim=83, activation="relu"))
    my_model.add(Dense(200, activation="relu"))
    my_model.add(Dense(200, activation="relu"))
    my_model.add(Dense(200, activation="relu"))
    my_model.add(Dense(32, activation="softmax"))

    return my_model


if __name__ == '__main__':
    data = import_data('data/data_cropped.csv')

    data = prepare_df(data)
    print(data.Shirts.nunique())
    X = to_categorical(data['Shirts'].values)
    y = data['Pants'].values

    optimizer = Adam(learning_rate=Learning_Rate)

    model = create_model()

    model.compile(
        loss="sparse_categorical_crossentropy",
        metrics=["sparse_categorical_accuracy"],
        optimizer=optimizer,
    )
    print("Fit model on training data")
    history = model.fit(
        x=X, y=y, epochs=Epochs, batch_size=Batch_Size, verbose=1, validation_data=(X, y))

I would appreciate if you could help me on this matter.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.