0

I have a trained autoencoder model which have developed by using tensor flow. Also, I have created a data frame from a dictionary. the dictionary is like below

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

After I convert this dictionary I entered into the below function,

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()

Once I put that into this function to enter it to the autoencoder model it gives below the message. enter image description here

It says that the data frame is empty. Then I checked the data frame by printing it. It gives me bellow result, enter image description here

After that, I have checked the result which is giving by the min_max_schaler.It has given below result,

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

I don't have an idea of why this problem is coming to me. Please help me to fix this issue.

I have checked below questions but it not worked for me yet.

Sklearn's MinMaxScaler only returns zeros

Code returns empty dataframe without index

Theesh
  • 187
  • 1
  • 18
  • I see three different dataframes in your outputs. In the error, the df starts with `type, sameorig` and ends with `is_anomaly`. In the print, there is one that starts with `step` and ends with `newBalacnedest`, and one that starts with `type` and ends with `is_transfer`. I am wondering if you're feeding in the correct DF to your model? – G. Anderson Jun 11 '19 at 19:22
  • Here I'm adding that columns before the feeding it. Because the autoencoder is needed those values. If you carefully look at my code, you can understand why i was doing that – Theesh Jun 11 '19 at 19:24

0 Answers0