Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

name 'Sequential' is not defined Python3 Keras

import numpy
import keras.models
import tensorflow
seed = 7

numpy.random.seed(seed)
dataset = numpy.genfromtxt("student-por.csv",delimiter=";")
X = dataset[:,0:33]
Y = dataset[:,8]
model = Sequential()
model.add(Dense(12, input_dim=8, init='uniform', activation='relu'))
model.add(Dense(8, init='uniform', activation='relu'))
model.add(Dense(1, init='uniform', activation='sigmoid'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) # Fit the model

scores = model.evaluate(X,Y)
print("%s: %s" % (model.metrics_names[1], scores[1]*100))

Error :

#Exception 错误: #Using TensorFlow backend. #Traceback (most recent call last): # File "test.py", line 11, in # model = Sequential() #NameError: name 'Sequential' is not defined #很奇怪 他居然显示Sequential()有问题 我确认好多次我没打错了 引用库也不知道有什么问题

It is strange that he actually showed that there is a problem with Sequential (). I confirmed many times that I did not type the reference library incorrectly and did not know what was wrong.

like image 354
user13126714 Avatar asked Mar 26 '20 06:03

user13126714


People also ask

What does sequential () do in Python?

Sequential API is used to create models layer-by-layer. Functional API is an alternative approach of creating more complex models. Functional model, you can define multiple input or output that share layers. First, we create an instance for model and connecting to the layers to access input and output to the model.

What is TF Keras sequential?

tf.keras.Sequential(layers=None, name=None) The Keras sequential class helps to form a cluster of a layer that is linearly stacked into tf. keras. Model. The features of training and inference are provided by sequential to this model.

What is sequential in TensorFlow?

A Sequential model is appropriate for a plain stack of layers where each layer has exactly one input tensor and one output tensor. Schematically, the following Sequential model: # Define Sequential model with 3 layers. model = keras.

What function should you use to train a Keras sequential model?

Fit Keras Model You can train or fit your model on your loaded data by calling the fit() function on the model. Training occurs over epochs, and each epoch is split into batches.


1 Answers

You should import it.

from keras.models import Sequential
like image 61
yishairasowsky Avatar answered Jan 03 '23 20:01

yishairasowsky