您可以声明一个自定义数值列并将其添加到输入函数中的数据框中:
# Existing features
age = tf.feature_column.numeric_column("age")
education_num = tf.feature_column.numeric_column("education_num")
# Declare a custom column just like other columns
my_feature = tf.feature_column.numeric_column("my_feature")
...
# Add to the list of features
feature_columns = { ... age, education_num, my_feature, ... }
...
def input_fn():
df_data = pd.read_csv("input.csv")
df_data = df_data.dropna(how="any", axis=0)
# Manually update the dataframe
df_data["my_feature"] = df_data["age"] * df_data["education_num"]
return tf.estimator.inputs.pandas_input_fn(x=df_data,
y=labels,
batch_size=100,
num_epochs=10)
...
model.train(input_fn=input_fn())