Kaggle系列-IEEE-CIS Fraud Detection第一名复现

赛题背景

想象一下,站在杂货店的收银台,身后排着长队,收银员没有那么安静地宣布您的信用卡被拒绝了。在这一刻,你可能没有想到决定你命运的数据科学。
非常尴尬有木有?当然你肯定有足够的资金为50个最亲密的朋友办一场盛大的纳乔派对,然后你又试了一次,但是还是同样的结果。此时你只能站在另外一边,让收银员为下一个客户服务时,你收到了银行的短信。“如果你真的想花500美元买切达干酪,请按1。”
虽然现在可能很麻烦(而且常常很尴尬),但这种防欺诈系统实际上每年为消费者节省数百万美元。来自ieee计算智能协会(ieee-cis)的研究人员希望在改善客户体验的同时,提升这个数字。有了更高准确度的欺诈检测率,您就可以在没有麻烦的情况下继续使用您的芯片。
ieee-cis在各种人工智能和机器学习领域,包括深层神经网络、模糊系统、演化计算和群智能等等。今天,他们正与世界领先的支付服务公司Vesta Corporation合作,为防欺诈行业寻求最佳解决方案,现在邀请您也加入此次挑战。
在本次竞赛中,您将在一个具有挑战性的大型数据集上对你的机器学习模型进行基准测试。这些数据来自Vesta的真实电子商务交易,并且包含了从设备类型到产品功能的各种特征。您还可以创建新的特征来改善结果。
如果成功,您将提高全球数百万人的欺诈交易警报的有效性,帮助数十万企业减少欺诈损失并增加收入。当然,你也可以为你自己减少误报的麻烦。

致谢:
Vesta公司为这次竞争提供了数据集。Vesta公司是保证电子商务支付解决方案的先驱。维斯塔公司成立于1995年,开创了电信行业无担保卡(CNP)支付交易的先河。此后,Vesta在全球范围内坚定地扩展了数据科学和机器学习能力,巩固了其在保证电子商务支付方面的领先地位。如今,Vesta每年为超过180亿美元的交易提供担保。

Magic Feature

https://www.kaggle.com/cdeotte/xgb-fraud-with-magic-0-9600

# frequency encode
def encode_FE(df1, df2, cols):
    for col in cols:
        df = pd.concat([df1[col], df2[col]])
        vc = df.value_counts(dropna=True, normalize=True).to_dict()
        vc[-1] = -1
        nm = col + "FE"
        df1[nm] = df1[col].map(vc)
        df1[nm] = df1[nm].astype("float32")
        df2[nm] = df2[col].map(vc)
        df2[nm] = df2[nm].astype("float32")
        print(col)


# label encode
def encode_LE(col, train=X_train, test=X_test, verbose=True):
    df_comb = pd.concat([train[col], test[col]], axis=0)
    df_comb, _ = pd.factorize(df_comb[col])
    nm = col
    if df_comb.max() > 32000:
        train[nm] = df_comb[0: len(train)].astype("float32")
        test[nm] = df_comb[len(train):].astype("float32")
    else:
        train[nm] = df_comb[0: len(train)].astype("float16")
        test[nm] = df_comb[len(train):].astype("float16")
    del df_comb
    gc.collect()
    if verbose:
        print(col)


def encode_AG(main_columns, uids, aggregations=["mean"], df_train=X_train, df_test=X_test, fillna=True, usena=False):
    for main_column in main_columns:
        for col in uids:
            for agg_type in aggregations:
                new_column = main_column + "_" + col + "_" + agg_type
                temp_df = pd.concat([df_train[[col, main_column]], df_test[[col, main_column]]])
                if usena:
                    temp_df.loc[temp_df[main_column] == -1, main_column] = np.nan

                #求每个uid下,该col的均值或标准差
                temp_df = temp_df.groupby([col])[main_column].agg([agg_type]).reset_index().rename(
                    columns={agg_type: new_column})
                #将uid设成index
                temp_df.index = list(temp_df[col])
                temp_df = temp_df[new_column].to_dict()
                #temp_df是一个映射字典
                df_train[new_column] = df_train[col].map(temp_df).astype("float32")
                df_test[new_column] = df_test[col].map(temp_df).astype("float32")
                if fillna:
                    df_train[new_column].fillna(-1, inplace=True)
                    df_test[new_column].fillna(-1, inplace=True)
                print(new_column)


# COMBINE FEATURES交叉特征
def encode_CB(col1, col2, df1=X_train, df2=X_test):
    nm = col1 + '_' + col2
    df1[nm] = df1[col1].astype(str) + '_' + df1[col2].astype(str)
    df2[nm] = df2[col1].astype(str) + '_' + df2[col2].astype(str)
    encode_LE(nm, verbose=False)
    print(nm, ', ', end='')


# GROUP AGGREGATION NUNIQUE
def encode_AG2(main_columns, uids, train_df=X_train, test_df=X_test):
    for main_column in main_columns:
        for col in uids:
            comb = pd.concat([train_df[[col] + [main_column]], test_df[[col] + [main_column]]], axis=0)
            mp = comb.groupby(col)[main_column].agg(['nunique'])['nunique'].to_dict()
            train_df[col + '_' + main_column + '_ct'] = train_df[col].map(mp).astype('float32')
            test_df[col + '_' + main_column + '_ct'] = test_df[col].map(mp).astype('float32')
            print(col + '_' + main_column + '_ct, ', end='')

链接:https://zhuanlan.zhihu.com/p/85947569

IEEE-CIS Fraud Detection is a Kaggle competition that challenges participants to detect fraudulent transactions using machine learning techniques. KNN (k-Nearest Neighbors) is one of the machine learning algorithms that can be used to solve this problem. KNN is a non-parametric algorithm that classifies new data points based on the majority class of their k-nearest neighbors in the training data. In the context of fraud detection, KNN can be used to classify transactions as either fraudulent or not based on the similarity of their features to those in the training data. To implement KNN for fraud detection, one can follow the following steps: 1. Preprocess the data: This involves cleaning and transforming the data into a format that the algorithm can work with. 2. Split the data: Split the data into training and testing sets. The training data is used to train the KNN model, and the testing data is used to evaluate its performance. 3. Choose the value of k: This is the number of neighbors to consider when classifying a new data point. The optimal value of k can be determined using cross-validation. 4. Train the model: Train the KNN model on the training data. 5. Test the model: Test the performance of the model on the testing data. 6. Tune the model: Fine-tune the model by changing the hyperparameters such as the distance metric used or the weighting function. Overall, KNN can be a useful algorithm for fraud detection, but its performance depends heavily on the quality of the data and the choice of hyperparameters.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值