我試圖分析數據集60列(FEATURES = 59列(整數和浮點數)的組合,LABEL =列名爲TARGET 0 /值爲1)Tensorflow DNNClassifier.fit錯誤:類型錯誤:「元組」對象不是可調用
我得到以下錯誤,而試圖擬合模型:
TypeError: 'tuple' object is not callable
以下是所使用的代碼:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import urllib
import itertools
import pandas as pd
import numpy as np
import tensorflow as tf
tf.logging.set_verbosity(tf.logging.INFO)
COLUMNS = ["DEMAdmNo","target","PEV_30","PEV_365","lhlos","LTSD","LNOSD","comorbidity_index","AdmD_3","AdmD_7","AdmD_8","AdmD_9","AdmD_11","AdmD_13","AdmD_14","AdmD_15","AdmD_16","AdmD_18","AdmD_20","AdmD_21","AdmD_22","AdmD_23","AdmD_26","AdmD_27","AdmD_28","AdmD_30","AdmD_31","AdmD_32","AdmD_33","AdmD_36","DisP_1","DisP_2","DisP_4","DisP_5","DisP_6","DisP_7","DisP_11","DisP_12","DisP_13","DisP_14","DisP_16","Disc_8","Disc_10","Disc_11","Disc_12","Disc_14","Disc_15","Disc_17","Disc_21","Disc_22","Disc_23","Disc_24","Disc_25","Disc_26","Disc_27","Disc_28","Disc_29"]
FEATURES = ["DEMAdmNo","PEV_30","PEV_365","lhlos","LTSD","LNOSD","comorbidity_index","AdmD_3","AdmD_7","AdmD_8","AdmD_9","AdmD_11","AdmD_13","AdmD_14","AdmD_15","AdmD_16","AdmD_18","AdmD_20","AdmD_21","AdmD_22","AdmD_23","AdmD_26","AdmD_27","AdmD_28","AdmD_30","AdmD_31","AdmD_32","AdmD_33","AdmD_36","DisP_1","DisP_2","DisP_4","DisP_5","DisP_6","DisP_7","DisP_11","DisP_12","DisP_13","DisP_14","DisP_16","Disc_8","Disc_10","Disc_11","Disc_12","Disc_14","Disc_15","Disc_17","Disc_21","Disc_22","Disc_23","Disc_24","Disc_25","Disc_26","Disc_27","Disc_28","Disc_29"]
LABEL = "target"
# Load datasets
training_set = pd.read_csv("Performance_train_jun5.csv", skipinitialspace=True,skiprows=1, names=COLUMNS)
test_set = pd.read_csv("Performance_test_jun5.csv", skipinitialspace=True,skiprows=1, names=COLUMNS)
def my_input_fn(data_set):
feature_cols = {k: tf.constant(data_set[k].values)
for k in FEATURES}
labels = tf.constant(data_set[LABEL].values)
return feature_cols, labels
classifier =
tf.contrib.learn.DNNClassifier(feature_columns=my_input_fn(training_set),
hidden_units=[10, 20, 10],
n_classes=2,
model_dir="/tmp/h_model")
INFO:tensorflow:Using default config.
INFO:tensorflow:Using config: {'_evaluation_master': '', '_task_type': None, '_num_ps_replicas': 0, '_keep_checkpoint_every_n_hours': 10000, '_master': '', '_num_worker_replicas': 0, '_save_checkpoints_steps': None, '_model_dir': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x000000000DA51908>, '_keep_checkpoint_max': 5, '_save_checkpoints_secs': 600, '_tf_config': gpu_options {
per_process_gpu_memory_fraction: 1
}
, '_tf_random_seed': None, '_task_id': 0, '_environment': 'local', '_save_summary_steps': 100, '_is_chief': True}
classifier.fit(input_fn=my_input_fn(training_set), steps=2000)
TypeError: 'tuple' object is not callable
關於上面的代碼,我有以下問題:
1)由於我的功能是int和float數據類型的混合,它們會在將它們轉換爲張量時引發問題嗎?
2)我的理解是,在classifier.fit的my_input_fn呼叫應閱讀功能和目標數據。我在這裏錯過了什麼嗎?第一
我曾試圖將int特性強制浮動,它似乎工作。我將進一步研究預處理。感謝您的輸入! –