我有一个既包含分类元素又包含数字元素的数据。 为了从Tensorflow进行DNN回归,我尝试制作要素列。
s.a=[1 2 3 4 5 6]';
s.b=[5 2 8 1 0 4]';
s.c=[9 7 0 1 3 5]';
lowest_row=2;
highest_row=4;
num_of_fields=length(fieldnames(s)); % Will be 25 in your code
mat = struct2array(s); % Convert struct to matrix
extracted_mat = mat(lowest_row:highest_row,:); % Extract wanted rows from mat
abc_vec=char(97:122);
% Convert back to struct
for i=1:num_of_fields
t.(abc_vec(i))=extracted_mat(:,i);
end
X_train数据的类型是pandas DataFrame。
features_categorical = X_train_categorical.columns
features_numeric= X_train_numeric.columns
然后我尝试进行转换,出现此消息。
feature_col_categorical = [tf.feature_column.indicator_column(i) for i in X_train_categorical]
feature_col_numeric = [tf.feature_column.numeric_column(k) for k in X_train_numeric]
regressor = tf.estimator.DNNRegressor(
feature_columns = [feature_col_categorical, feature_col_numeric],hidden_units=[10, 10])
train_input_fn = tf.estimator.inputs.pandas_input_fn(
x= {'x' : X_train}, y=y_train['06'], batch_size=1, num_epochs=None, shuffle=True)
regressor.train(input_fn=train_input_fn, steps=20000)
我认为它将第一个feature_columns的元素视为列表。 因此,我创建了一个功能以一次创建要素列。 但这也行不通。
Items of feature_columns must be a _FeatureColumn. Given (type <class 'list'>): [_IndicatorColumn(categorical_column='date'),
_IndicatorColumn(categorical_column='days'),
_IndicatorColumn(categorical_column='name'),
_IndicatorColumn(categorical_column='ID')].
我该如何解决这个问题?