小编Tul*_*mak的帖子

feature_columns的项必须是_FeatureColumn

我收到此错误:

ValueError:feature_columns的项必须是_FeatureColumn.给定(类型):索引(['CreditScore','Age','Tenure','Balance','NumOfProducts','HasCrCard','IsActiveMember','EstimatedSalary','Exited'],dtype ='object' ).

我正在使用tensorFlow lib.我想获得预测结果,但我无法运行m.train(input_fn=get_input_fn ,steps=5000)代码.无论我做什么,我总是得到同样的错误.我在下面使用了这些输入函数,但没有改变.

def input_fn_train():
     x=tf.constant(df_train.astype(np.float64)),
     y=tf.constant(df_train[LABEL].astype(np.float64))
     return x, y
Run Code Online (Sandbox Code Playgroud)

def get_input_fn(data_set, num_epochs=None, shuffle=False):
     return tf.estimator.inputs.pandas_input_fn(
      x=pd.DataFrame({k: data_set[k].values for k in data_set.columns}),
      y=pd.Series(data_set[LABEL].values), num_epochs=num_epochs,
                  shuffle=shuffle)
Run Code Online (Sandbox Code Playgroud)

我无法理解我该怎么做.错误是什么?我一直在谷歌搜索,但从未找到有用的东西.我该如何处理这个错误.代码如下.谢谢!

import pandas as pd
import tensorflow as tf
import numpy as np
import tempfile

COLS= ["RowNumber","CustomerId","Surname","CreditScore","Geography",
"Gender","Age","Tenure","Balance","NumOfProducts","HasCrCard",
"IsActiveMember","EstimatedSalary","Exited"]


FEATURES = ["CreditScore","Age","Tenure","Balance","NumOfProducts",
       "HasCrCard","IsActiveMember", "EstimatedSalary"]

LABEL="Exited"

df_train = pd.read_csv("Churn_Modelling.csv", skipinitialspace=True, 
header=0)
df_test = pd.read_csv("Churn_Modelling.csv", skipinitialspace=True, 
header=0)
test_label = df_test[LABEL].astype(float)
df_test.drop("Surname", axis = 1, inplace=True)
df_test.drop("RowNumber", axis = 1, inplace=True) …
Run Code Online (Sandbox Code Playgroud)

python machine-learning feature-selection deep-learning tensorflow

3
推荐指数
2
解决办法
4590
查看次数