In the wide_n_deep tutorial code, the below two line:
df_train[LABEL_COLUMN] = (df_train["label"].apply(lambda x: '>50K' in x)).astype(int)
df_test[LABEL_COLUMN] = (df_test["label"].apply(lambda x: '>50K' in x)).astype(int)
change the label column from string
to int
. However, it seems that this kind of operation only works well on two-classes classification data sets, ie, yes
or no
, 1
or 0
problems.
Now I hope to apply the wide and deep model on more classes, especially numerical data than string data. But I got TypeError: argument of type 'float' is not iterable
I have also tried to delete the codes transforming label columns to int
, which shown above, and I got tensorflow.contrib.learn.python.learn.monitors.NanLossDuringTrainingError: NaN loss during training.
So how can I solve those problems? Can't the wide_n_deep model make use for multi-classification?
如果产生的标签范围大于0或1,则宽和深估计量会支持多类分类。
You can do it on a float column :
df_train[LABEL_COLUMN] = df_train["float_column"].astype(float)
But I have 0.0 accuracy ... maybe this not the right answer but it shows no errors.
If you are still looking to solve this. tf r1.1 has an argument n_classes
estimator = DNNLinearCombinedClassifier(
# common settings
n_classes=n_classes,
weight_column_name=weight_column_name,
# wide settings
linear_feature_columns=[sparse_feature_a_x_sparse_feature_b],
linear_optimizer=tf.train.FtrlOptimizer(...),
# deep settings
dnn_feature_columns=[sparse_feature_a_emb, sparse_feature_b_emb],
dnn_hidden_units=[1000, 500, 100],
dnn_optimizer=tf.train.AdagradOptimizer(...))
n_classes: number of label classes. Default is binary classification. Note that class labels are integers representing the class index (ie values from 0 to n_classes-1). For arbitrary label values (eg string labels), convert to class indices first.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.