1

So for an application I'm making I'm using tf.keras.models.Sequential. I know that there are linear and multilinear regression models for machine learning. In the documentation of Sequential is said that the model is a linear stack of layers. Is that equal to multilinear regression? The only explaination of linear stack of layers I could find was this question on Stackoverflow.

def trainModel(bow,unitlabels,units):
    x_train = np.array(bow)
    print("X_train: ", x_train)
    y_train = np.array(unitlabels)
    print("Y_train: ", y_train)
    model = tf.keras.models.Sequential([
            tf.keras.layers.Dense(256, activation=tf.nn.relu),
            tf.keras.layers.Dropout(0.2),
            tf.keras.layers.Dense(len(units), activation=tf.nn.softmax)])
    model.compile(optimizer='adam',
                         loss='sparse_categorical_crossentropy',
                         metrics=['accuracy'])
    model.fit(x_train, y_train, epochs=50)
    return model

2 Answers2

0

you are confusing two things very important here. One is the model and the other is the model of the model.

  • The model of the model is indeed a linear one because it follows a direct line (straightforward) from beginning till end.

  • the model itself is not linear: The relu activation is here to make sure that the solutions are not linear.

the linear stack is not a linear regression nor a multilinear one. The linear stack is not a ML term here but the english one to say straightforward. tell me if i misunderstood the question in any regard.

Frayal
  • 2,117
  • 11
  • 17
  • So Sequential is linear but the output of my model is not linear because of the relu activation? or is the model I'm making also not linear? – thomas dees May 06 '19 at 13:10
  • 1
    yes the model is "linear" as a linear (direct) stack of layer. No the model is not linear as the output is not a linear combination of the inputs (plus a static term). – Frayal May 06 '19 at 13:15
  • What would be the term to describe the model output then? if not linear – thomas dees May 06 '19 at 13:18
  • 1
    non-linear. (we can't be more precise in this case). see this question/answer for more infos https://stackoverflow.com/questions/41244421/linear-vs-nonlinear-neural-network – Frayal May 06 '19 at 13:31
0

In the documentation of Sequential is said that the model is a linear stack of layers. Is that equal to multilinear regression?

Assuming you mean a regression with multiple variables, no.

tf.keras.models.Sequential() defines how the layers in your model are connecting, specifically in this case it means they are fully connected (every output from the first layer is connected as an input to every neuron in the next layer). The term linear is used to mean that there is no funny business going on, e.g. recurrency (connections can go backwards) or residual connections (connections can skip layers).

For context, a regression with multiple variables is comparable to a single layered network with a single neuron with multiple inputs and no transfer function.

itwasthekix
  • 585
  • 6
  • 11