为什么给出空数据框消息?

时间:2019-06-11 18:47:01

标签: python pandas tensorflow scikit-learn

我有一个受过训练的自动编码器模型,该模型是通过使用张量流开发的。另外,我已经从字典创建了一个数据框。字典如下所示

{'step': '4', 'type': 'CASH_IN', 'amount': '100000', 'nameOrig': 'C1666544295', 'oldBalanceOrig': '1096835345345', 'newBalanceOrig': '61652353534545.23', 'nameDest': 'M1979787155', 'oldBalanceDest': '1.2312322342353452e+21', 'newBalacneDest': '827467862345345400'}

转换字典后,我进入了以下功能

def get_predictions_for_live_transactions(train_set, model_path):
    x_lables = train_set[['type', 'nameOrig', 'nameDest']].copy()
    x_lables = pd.DataFrame(x_lables)
    # print('here', x_lables)
    train_set = train_set.drop(['nameOrig', 'nameDest', 'step'], axis=1)
    # print(train_set['type'].values[0])
    # exit()
    if train_set['type'].values[0] == 'DEBIT':
        train_set['is_CASH_IN'] = 0
        train_set['is_CASH_OUT'] = 0
        train_set['is_DEBIT'] = 1
        train_set['is_PAYMENT'] = 0
        train_set['is_TRANSFER'] = 0
    elif train_set['type'].values[0] == 'PAYMENT':
        train_set['is_CASH_IN'] = 0
        train_set['is_CASH_OUT'] = 0
        train_set['is_DEBIT'] = 0
        train_set['is_PAYMENT'] = 1
        train_set['is_TRANSFER'] = 0
    elif train_set['type'].values[0] == 'TRANSFER':
        train_set['is_CASH_IN'] = 0
        train_set['is_CASH_OUT'] = 0
        train_set['is_DEBIT'] = 0
        train_set['is_PAYMENT'] = 0
        train_set['is_TRANSFER'] = 1
    elif train_set['type'].values[0] == 'CASH_OUT':
        train_set['is_CASH_IN'] = 0
        train_set['is_CASH_OUT'] = 1
        train_set['is_DEBIT'] = 0
        train_set['is_PAYMENT'] = 0
        train_set['is_TRANSFER'] = 0
    elif train_set['type'].values[0] == 'CASH_IN':
        train_set['is_CASH_IN'] = 1
        train_set['is_CASH_OUT'] = 0
        train_set['is_DEBIT'] = 0
        train_set['is_PAYMENT'] = 0
        train_set['is_TRANSFER'] = 0
    else:
        pass
    print(train_set)
    # print(train_set.columns)
    # exit()
    train_set = train_set.drop(['type'], axis=1)
    new_df = pd.concat([x_lables, train_set], axis=1)
    new_df = new_df.drop(['is_CASH_IN', 'is_CASH_OUT', 'is_DEBIT', 'is_PAYMENT', 'is_TRANSFER'], axis=1)  # here chaged
    # print(train_set.columns.values)
    # exit()
    saver = None
    sess = tf.Session()
    num_input = 10
    result_errors = []
    try:
        saver = tf.train.import_meta_graph(model_path + 'general.meta')
        print("successfully loaded the model")
        saver.restore(sess, tf.train.latest_checkpoint(model_path))
        graph = tf.get_default_graph()
        # print(train_set)
        np_scaled = min_max_scaler.fit_transform(train_set)
        # print(np_scaled)
        train_set = pd.DataFrame(np_scaled)
        print(train_set.iloc[0])
        # exit()
        for i in range(len(train_set)):
            print(i)
            # exit()
            X = graph.get_tensor_by_name("x:0")
            # print(X)
            decorder_op = graph.get_tensor_by_name("decoder_op:0")
            # g = sess.run(decorder_op, feed_dict={X: train_set.iloc[i].values.reshape(1, num_input)})
            feed_dict_testing = {X: train_set.iloc[i].values.reshape(1, num_input)}
            g = sess.run(decorder_op, feed_dict=feed_dict_testing)
            # print(g)

            error = np.sum(abs(train_set.iloc[i].values - g))
            # print(error)
            result_errors.append(error)

        new_df['result_errors'] = result_errors
        return new_df
    except IOError as e:
        print('No Trained Model Found at %s. \nPlease run train.py first', model_path)
        exit()

一旦我将其放入此函数以将其输入到消息下方的自动编码器模型中即可。 enter image description here

它表示数据框为空。然后,我通过打印检查了数据框。它给了我下面的结果 enter image description here

之后,我检查了min_max_schaler给出的结果。它给出了以下结果,

[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]

我不知道为什么这个问题来了。请帮助我解决此问题。

我已经检查了以下问题,但对我而言仍然无效。

Sklearn's MinMaxScaler only returns zeros

Code returns empty dataframe without index

0 个答案:

没有答案