Python 线性分类中训练模型的误差

Python 线性分类中训练模型的误差,python,tensorflow,machine-learning,classification,training-data,Python,Tensorflow,Machine Learning,Classification,Training Data,我是Tensorflow的新手,我希望在这里能得到一些帮助,我正在尝试做一个线性分类,它有三个输入和一个输出,这看起来像Tensorflow中的一个简单任务,但我仍然得到这个错误: WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/training/training_util.py:236: Variable.initialized_value (from tensorflow.pyt

我是Tensorflow的新手,我希望在这里能得到一些帮助,我正在尝试做一个线性分类,它有三个输入和一个输出,这看起来像Tensorflow中的一个简单任务,但我仍然得到这个错误:

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/training/training_util.py:236: Variable.initialized_value (from tensorflow.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Use Variable.read_value. Variables in 2.X are initialized automatically both in eager and graph (inside tf.defun) contexts.
INFO:tensorflow:Calling model_fn.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow_estimator/python/estimator/canned/linear.py:1481: Layer.add_variable (from tensorflow.python.keras.engine.base_layer_v1) is deprecated and will be removed in a future version.
Instructions for updating:
Please use `layer.add_weight` method instead.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/optimizer_v2/ftrl.py:112: calling Constant.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:Calling checkpoint listeners before saving checkpoint 0...
INFO:tensorflow:Saving checkpoints for 0 into /tmp/tmpzjg63e2x/model.ckpt.
INFO:tensorflow:Calling checkpoint listeners after saving checkpoint 0...
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
   1364     try:
-> 1365       return fn(*args)
   1366     except errors.OpError as e:
17 frames
InvalidArgumentError: assertion failed: [Labels must be <= n_classes - 1] [Condition x <= y did not hold element-wise:] [x (head/losses/Cast:0) = ] [[3921243][304731][545457]...] [y (head/losses/check_label_range/Const:0) = ] [1]
     [[{{node Assert}}]]
During handling of the above exception, another exception occurred:
InvalidArgumentError                      Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
   1382                     '\nsession_config.graph_options.rewrite_options.'
   1383                     'disable_meta_optimizer = True')
-> 1384       raise type(e)(node_def, op, message)
   1385 
   1386   def _extend_graph(self):
InvalidArgumentError: assertion failed: [Labels must be <= n_classes - 1] [Condition x <= y did not hold element-wise:] [x (head/losses/Cast:0) = ] [[3921243][304731][545457]...] [y (head/losses/check_label_range/Const:0) = ] [1]
     [[{{node Assert}}]]
def make_input_fn,label_df, num_epochs=10, shuffle=True, batch_size=32:
def input_function():  
ds = tf.data.Dataset.from_tensor_slices((dict(data_df), label_df)) 
if shuffle:
ds = ds.shuffle(1000) 
ds = ds.batch(batch_size).repeat(num_epochs)
return ds  
return input_function 
train_input_fn = make_input_fn(tx_data, y_train)  
eval_input_fn = make_input_fn(df, y_eval, num_epochs=1, shuffle=False)
linear_est = tf.estimator.LinearClassifier(feature_columns=feature_columns)
linear_est.train(train_input_fn)  # train
result = linear_est.evaluate(eval_input_fn) 
clear_output() 
print(result['accuracy'])