Home>

Why should each sample in model.fit have the same size?

Before, with the link https://www.tutorialfor.com/go.php?id=141258

model.fit ([inputs_train, queries_train], answers_train,
          batch_size = 30,
          epochs = 100,
          validation_data = ([inputs_test, queries_test], answers_test))


I asked you that there was an error in the line. As a result, it turned out that an error appears because the list size of inputs_test and queries_test is different.

But why should the data sizes of the two trains and the two tests be the same? Why does the error occur otherwise?
I can't understand that.

  • Answer # 1

    fit is a method for learning a model, but it may be easy to understand what it means to learn.

    https://keras.rstudio.com/reference/fit.html

    Basically, learning proceeds by inputting one learning data (x, train data) for one teacher data (y, target data, label data) (calculating weights) Go). Each piece of data is represented by a single line, and multiple items of data are specified together.
    So the teacher data and learning data lines must match.
    In this case, it is normal that the columns are different, and it is common to obtain a single result for multiple training data.

    This is the same when specifying with validation_data. Using the data specified there, we can see what kind of result is obtained by giving a set similar to the training data, but it is specified in validation_data. The rows must match to evaluate it row by row. (Aside) In the case of validation_split, evaluation is performed by picking up the ratio specified from x and y, but the ratio to the total number of rows is specified.

  • Answer # 2

    In order to perform arithmetic operations between tenors, both types must match.
    However, you can increase or decrease the column depending on the model structure, so you don't have to worry too much about the input value. On the other hand, the row (number of samples) generally retains the value at the time of input, so it cannot be calculated unless it is matched in advance