从零开始在出租车中创建反欺诈系统

下午好。我叫Nikita Bashun,我是Lucky集团公司的数据分析师。我的故事将是关于我们如何由三个人组成的团队从头开始为旅行预订服务创建一个反欺诈系统。



图片



介绍



曾经知道如何欺骗的人会欺骗很多次。

洛佩·德·维加

在本案中,欺诈是驾驶员欺骗公司的情况。骗取钱财。



, , 25, Delphi. . , . , . …





— MVP, .

, :



  • . ( «-» ), , . ;
  • . — , ( , ). -, 200 .
  • , — « »:

    • , (, 0% );
    • , -.


图片



:



  • — , , , ;
  • - ( ) — , , ;
  • — , , , .








图片



SQL- DWH, . . , , «»:



WHERE susp = 1 --   
  AND finished_orders >= 3 --        
  AND cancelled >= 3 --    ,        
  AND dist_fin_drivers <= 2 --      
  AND ok <= 2 --   2-     


, .



. « » . , ? -. , .



图片



python. pandas, postgres, Google ( ). , , Apache Airflow.



API .

:



credentials = ServiceAccountCredentials.from_json_keyfile_dict(
    config.crd,
    ['https://www.googleapis.com/auth/spreadsheets',
     'https://www.googleapis.com/auth/drive'])

httpAuth = credentials.authorize(httplib2.Http())
service = googleapiclient.discovery.build('sheets', 'v4', http=httpAuth)
sheet = service.spreadsheets()


:



base_range = f'{city_name}!A{ss_row + 1}:Z{ss_row + reserved_rows}'
sheet.values().append(spreadsheetId=spreadsheetid,
                                 range=base_range,
                                 body={"values": df_pos.values.tolist()},
                                 valueInputOption='RAW').execute()


:



range_from_ss = f'{city_name}!A{ss_row}:S{ss_row + reserved_rows}'

data_from_ss = service.spreadsheets().values().get(
            spreadsheetId=spreadsheetid,
            range=range_from_ss).execute().get('values', [])

data_from_ss = pd.DataFrame(data_from_ss)
data_from_ss_cols = ['id', '', '']
data_from_ss = data_from_ss.loc[1:, data_from_ss_cols]


PG:



vls_ss = ','.join([f"""({', '.join([f(d[c]) for c in data_from_ss_cols])}
                    )""" for d in data_from_ss.to_dict('rows')])

sql_update = f"""
    WITH updated as (
        UPDATE fraud_billing
        SET resolution = tb.resolution,
            comment=tb.comment,
            dt = NOW()
        FROM (VALUES {vls_ss}) AS tb(fraud_billing_id, resolution, comment)
        WHERE fraud_billing.fraud_billing_id = CAST(tb.fraud_billing_id AS INTEGER)
            AND ((fraud_billing.resolution IS NULL AND tb.resolution IS NOT NULL)
                OR (fraud_billing.comment IS NULL AND tb.comment IS NOT NULL)
                OR (fraud_billing.comment IS NOT NULL AND tb.comment IS NOT NULL
                   AND fraud_billing.comment <> tb.comment)
                OR (fraud_billing.resolution IS NOT NULL AND tb.resolution IS NOT NULL
                    AND fraud_billing.resolution <> tb.resolution)
               )
        RETURNING {alias_cols_text_with_id}
        )
    INSERT INTO fraud_billing_history ({cols_text_with_id})
    SELECT {cols_text_with_id}
    FROM updated;
"""

crs_postgres.execute(sql_update)
con_postgres.commit()


postgres :



  • ;
  • .


:



图片



( , ).



, :



图片



— .



: , , .



.



, . , , — . «» .



图片



FP- , .



— , , . .



« ». , , :



  • ;
  • ;
  • ;
  • — .


.



, . , , , , . - :



图片



, , — .



Google Spreadsheets. . , :



  • , «» ;
  • API — ;
  • ;
  • , .




. , — :



  • . - , - , - . , . ;
  • . , , :

    • - , ;
    • - ;
    • - , ;
    • - .


, , . , «».



— , . — , . !




, ?



  • . . , «» , . ;
  • . , . , .


( ) 35%. — 25%. , — — , . : , , , . .



图片



:



  • 15 ;
  • 6800 ;
  • 500 .


但是,最重要的成功是在许多城市,逐渐减少可疑案件。毕竟,理想情况下,我们不想抓到更多,我们什么也不想抓



结论



我试图描述反欺诈系统的主要功能和原理,以及我们遇到的困难。这些计划包括:使用ML优化搜索,创建制裁监视系统(现在处于初期阶段),改善管理人员的界面,创建动态报告,开发新模式等等。



毕竟,我们只是旅程的开始。




All Articles