[프로젝트 데이터 전처리]
“cards” 13개 컬럼 중에서
- 파생 컬럼1 "계좌 개설 경과 기간“ # 계좌를 오래 유지한 사람일수록 금융 신뢰도가 높다.
(datetime.now().year - df_cards['acct_open_date'],format='%m/%Y')
- ['card_type'] : 범주형 인코딩(레이블 인코딩)
- ['credit_limit'] : 체크 카드에도 카드 한도가 존재함을 확인.
- ['id'] : 카드 ID (카드 고유 식별자!)
# 버리는 컬럼
- year_pin_last_changed(PIN 마지막 변경 연도), card_on_dark_web(다크웹에서 카드 정보 발견 여부), num_cards_issued(발급된 카드 총 개수), has_chip(칩 유무(마그네틱 카드와 IC카드 구분)) cvv(카드 보안 코드), card_number, card_brand(애매한데?), client_id(고객 ID)
“users" 14개 컬럼 중에서
- 파생 컬럼1 : “소득 예상 기간” [‘retirement_age’] - [‘current_age’]
- 파생 컬럼2 : 'gender', 'age' 그룹핑
- 파생 컬럼3 : DTI(총 부채 상환 비율) [‘total_debt’] / ['yearly_Income'] (Debt-to-Income ratio)
# 버리는 컬럼
address(주소) latitude(주소의 위도) longitude(주소의 경도) per_capita_income(1인당 소득), birth_year(출생 연도), birth_month(출생 월), id(고객 ID), num_credit_cards(보유 신용카드 수)
“transactions” 12개 컬럼 중에서
[‘use_chip’] : 칩 사용 여부(온/오프라인 거래 여부)
[‘mcc’] : 총 8개의 범주 (레이블 인코딩 필요)
['error'] : 결측치(정상 결제 데이터), # 보류
[‘date'] : 거래 날짜
[‘client_id'] : 고객 ID
[‘card_id'] : 구분용 사용된 카드 ID
[‘amount'] :
# 버리는 컬럼
merchant_id(가맹점 고유 ID), merchant_city(가맹점 위치(도시)), merchant_state(가맹점 위치(주)) zip(가맹점 우편번호), id(거래 고유 ID)
최종 전처리
cards_data
- cards_data의 card_on_dark_web데이터는 No 밖에 없으므로 삭제해도 될듯
- 계좌 개설 경과 기간 (파생변수_1)
from datetime import datetime
df_cards['acct_open_year'] = pd.to_datetime(df_cards['acct_open_date'],format = '%m/%Y').dt.year
#파생변수 account_age 생성
df_cards['account_age'] = datetime.now().year - df_cards['acct_open_year']
# 께좌를 오래 유지한 사람일수록 금융 신뢰도가 높다?
- 범주형 데이터는 card_type만 보면 될듯
- debit 카드 (체크 카드) : 사용 즉시 분인 계좌에서 출금
- 신용거래가 아님 → 금융 기관이 신용 리스크를 판단하기 어려움
- credit (신용카드) : 일정 한도 내에서 선결제, 후불정산
- 신용 거래 이력이 생김 → 신용 점수 산정의 주요 기준
- debit(prepaid) (선불형 카드) : 미리 충전해놓고 사용
- 신용 리스크 평가가 어려운 취약 고객층일 수 있음
- debit 카드 (체크 카드) : 사용 즉시 분인 계좌에서 출금
- 파생변수_1 : 계좌 개설 경과 기간 (파생변수_1)
from datetime import datetime
df_cards['acct_open_year'] = pd.to_datetime(df_cards['acct_open_date'],format = '%m/%Y').dt.year
#파생변수 account_age 생성
df_cards['account_age'] = datetime.now().year - df_cards['acct_open_year']
# 께좌를 오래 유지한 사람일수록 금융 신뢰도가 높다?
- 카드 한도
df_cards['credit_limit'] = df_cards['credit_limit'].replace('[\\$,]','',regex=True).astype(float)
- id
transcation_data
- 결합 전 transactions에서 무의미 컬럼 혹은 데이터 제거
- transactions_data의 거래 부분 ‘-’인 행을 0으로 변환 **
- use_chip : 온라인/오프라인 여부
- mcc
mcc 데이터 범주화
import pandas as pd
# 1. 데이터 로딩
df = pd.read_excel("mcc_visa_2024.xlsx")
df["MCC"] = df["mcc"].astype(str)
def get_mcc_category_groups(mcc):
if mcc.startswith(("58", "54", "53", "56", "57", "59")) or mcc in ["5499", "5921", "5912", "742", "763", "780"]:
return "음식/소비"
elif mcc.startswith(("41", "44", "45", "47", "75")) or mcc in ["5533", "1520", "4214", "3775"]:
return "교통/이동"
elif mcc.startswith("80"):
return "건강/의료"
elif mcc.startswith(("48", "63", "49", "60", "61", "62")):
return "금융/공과금"
elif mcc.startswith("70") or mcc.startswith("79") or mcc in ["7832", "7922", "7995"]:
return "여가/숙박"
elif mcc.startswith(("73", "17", "30", "33", "35", "36", "32", "52")) or mcc in ["5712", "5719", "5943", "7349"]:
return "주거/생활"
elif mcc.startswith("81") or mcc.startswith("82") or mcc.startswith("89") or mcc in ["5942", "5192", "5733", "7230", "5621", "5655"]:
return "교육/전문"
else:
return "음식/소비"
df["MCC"] = df["MCC"].astype(str)
df["상위카테고리"] = df["MCC"].apply(get_mcc_category_groups)
df[["MCC","상위카테고리"]].head(50)
- errors 데이터의 결측치 → 정상데이터라는 것
- 결측치를 제거하지 않고 사용시 : 거래 지표에 따라서 대체
- 결측치를 0으로 설정
user_data
- 파생변수_1 : 소득 예상 기간 retirement_age - current_age
- 주소 제외
파생변수_2 : 성별 & 나이별 그룹화- 파생 변수 생성 ⇒ *DTI(*총부채 상환 비율) = Total Debt / Yearly Income (Debt-to-Income ratio)