I'm new to ml and am trying out some tiny projects. I have this snippet.
import pandas as pd
import json
import logging
import numpy as np
import matplotlib.pyplot as plt
from utils.utils import fetch_data, preprocess_data_cls, scale_features
from sklearn.metrics.pairwise import cosine_similarity
with open('configs/config_nn.json', 'r', encoding='utf-8') as f:
config = json.load(f)
DATA_PATH = config["DATA_PATH_TRN"]
RANDOM_STATE = config["RANDOM_STATE"]
ARGUMENT = 'suspicious_nn'
fraud_nn_df = fetch_data('fraud_nn')
no_fraud_nn_df = fetch_data('no_fraud_nn')
suspicious_nn_df = fetch_data('suspicious_nn')
conc_df = pd.concat([fraud_nn_df.drop(columns=['label']), no_fraud_nn_df.drop(columns=['label'])], ignore_index=True)
conc_labels = pd.concat([fraud_nn_df['label'], no_fraud_nn_df['label']], ignore_index=True)
conc_prp, _ = preprocess_data_cls(conc_df, 'TRNC')
conc_prp_scaled = scale_features(conc_prp)
suspicious = suspicious_nn_df.drop(columns=['label'])
suspicious_prp, _ = preprocess_data_cls(suspicious, 'SPS')
suspicious_prp_scaled = scale_features(suspicious_prp)
suspicious_cosine_sim = cosine_similarity(suspicious_prp_scaled, conc_prp_scaled)
suspicious_nn_labels = []
for i in range(suspicious_nn_df.shape[0]):
most_similar_index = np.argmax(suspicious_cosine_sim[i])
suspicious_nn_labels.append(conc_labels.iloc[most_similar_index])
suspicious_nn_df['label'] = suspicious_nn_labels
print(suspicious_nn_df.head())
There are three dfs: one for fraud transactions (label 1), one for no fraud transactions (label 0), and one for questionable transactions (label -1). I'd like to classify the suspicious data based on whether it's closer to one or zero. Is the above technique appropriate?
Thank you in advance.