TypeError при попытке подбора последовательной модели - PullRequest
0 голосов
/ 12 апреля 2020

Я пытаюсь построить регрессионную модель с моими данными в pandas DataFrame с именем finalDf:

##Create train and test datasets and labels
twoktrain_dataset = finalDf.sample(frac=0.8, random_state=95)
twoktest_dataset=finalDf.drop(twoktrain_dataset.index)
twoktrain_labels=twoktrain_dataset.pop('MT')
twoktest_labels=twoktest_dataset.pop('MT')

##Build and compile model
def build_model():
  model = keras.Sequential([
    layers.Dense(1)
  ])

  optimizer = tf.keras.optimizers.Adadelta(1)

  model.compile(loss='mse',
                optimizer=optimizer,
                metrics=['mae', 'mse'])
  return model

modeltwok = build_model()

###Fit model
EPOCHS=20000
history=modeltwok.fit(
twoktrain_dataset.values, twoktrain_labels.values, shuffle=True, batch_size=10,
epochs=EPOCHS, validation_split=0.2, verbose=0, callbacks=[tfdocs.modeling.EpochDots()])

Затем я получаю это сообщение об ошибке после попытки подбора модель:

ValueError: TypeError: len () объекта без размера

Кто-нибудь может объяснить, что здесь происходит? Полное сообщение об ошибке ниже:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-21-900a2b119b43> in <module>
      2 history=modeltwok.fit(
      3 twoktrain_dataset.values, twoktrain_labels.values, shuffle=True, batch_size=10,
----> 4 epochs=EPOCHS, validation_split=0.2, verbose=0, callbacks=[tfdocs.modeling.EpochDots()])

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
    817         max_queue_size=max_queue_size,
    818         workers=workers,
--> 819         use_multiprocessing=use_multiprocessing)
    820 
    821   def evaluate(self,

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\engine\training_v2.py in fit(self, model, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
    319           # Training
    320           with training_context.on_epoch(epoch, ModeKeys.TRAIN) as epoch_logs:
--> 321             model.reset_metrics()
    322             if training_data_iter is None or recreate_training_iterator:
    323               if (training_data_iter is not None and

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\engine\training.py in reset_metrics(self)
   1017     metrics = self._get_training_eval_metrics()
   1018     for m in metrics:
-> 1019       m.reset_states()
   1020 
   1021     # Reset metrics on all the distributed (cloned) models.

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\metrics.py in reset_states(self)
    210     when a metric is evaluated during training.
    211     """
--> 212     K.batch_set_value([(v, 0) for v in self.variables])
    213 
    214   @abc.abstractmethod

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\backend.py in batch_set_value(tuples)
   3321     with ops.init_scope():
   3322       for x, value in tuples:
-> 3323         x.assign(np.asarray(value, dtype=dtype(x)))
   3324   else:
   3325     with get_graph().as_default():

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\ops\resource_variable_ops.py in assign(self, value, use_locking, name, read_value)
    816     # initialize the variable.
    817     with _handle_graph(self.handle):
--> 818       value_tensor = ops.convert_to_tensor(value, dtype=self.dtype)
    819       self._shape.assert_is_compatible_with(value_tensor.shape)
    820       assign_op = gen_resource_variable_ops.assign_variable_op(

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\framework\ops.py in convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, dtype_hint, ctx, accepted_result_types)
   1312 
   1313     if ret is None:
-> 1314       ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
   1315 
   1316     if ret is NotImplemented:

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\framework\tensor_conversion_registry.py in _default_conversion_function(***failed resolving arguments***)
     50 def _default_conversion_function(value, dtype, name, as_ref):
     51   del as_ref  # Unused.
---> 52   return constant_op.constant(value, dtype, name=name)
     53 
     54 

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\framework\constant_op.py in constant(value, dtype, shape, name)
    256   """
    257   return _constant_impl(value, dtype, shape, name, verify_shape=False,
--> 258                         allow_broadcast=True)
    259 
    260 

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\framework\constant_op.py in _constant_impl(value, dtype, shape, name, verify_shape, allow_broadcast)
    264   ctx = context.context()
    265   if ctx.executing_eagerly():
--> 266     t = convert_to_eager_tensor(value, ctx, dtype)
    267     if shape is None:
    268       return t

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\framework\constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
     94       dtype = dtypes.as_dtype(dtype).as_datatype_enum
     95   ctx.ensure_initialized()
---> 96   return ops.EagerTensor(value, ctx.device_name, dtype)
     97 
     98 

ValueError: TypeError: len() of unsized object
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...