unique_response_corporate = df_train['response_corporate'].unique()
print(unique_response_corporate)
# 대륙별로 response_corporate 값을 매핑하는 딕셔너리 생성
def map_to_continent(value):
mapping = {
'EU': ['LGEBN', 'LGEFS', 'LGEIS', 'LGEPH', 'LGEIL', 'LGEDG', 'LGEUK', 'LGEPS', 'LGETK', 'LGELF', 'LGEPT', 'LGEPR', 'LGERO', 'LGEMK', 'LGEPL', 'LGECZ', 'LGEES', 'LGEHS', 'LGEEB', 'LGETT'],
'AS_PC': ['LGEPH', 'LGEIL', 'LGESL', 'LGEKR', 'LGEAP', 'LGEIN', 'LGEHK', 'LGEML', 'LGEJP', 'LGETH', 'LGEVH', 'LGECH'],
'ME_AF': ['LGEAF', 'LGESJ', 'LGEGF', 'LGESA', 'LGEEG', 'LGEEF', 'LGETK', 'LGELF', 'LGEAS', 'LGEMC', 'LGEAR', 'LGEIR'],
'N_AM': ['LGEUS', 'LGEMS', 'LGECI'],
'L_AM': ['LGECL', 'LGESP', 'LGECB', 'LGEPS', 'LGECB', 'LGEMS', 'LGEMC', 'LGEAG', 'LGEPS', 'LGEEB', 'LGESW', 'LGEYK'],
'R_CIS': ['LGERA', 'LGEUR', 'LGELA'],
'Unknown': ['LGEBT']
}
for continent, companies in mapping.items():
if value in companies:
return continent
return value
# df_train DataFrame에서 expected_timeline 열의 모든 값을 문자열로 변환
df_train['response_corporate'] = df_train['response_corporate'].astype(str)
# 데이터프레임에 함수 적용
df_train['response_corporate'] = df_train['response_corporate'].apply(map_to_continent)
print(df_train)
df_train['response_corporate'].value_counts()
# expected timeline 문구 대체 시도
# 0-3:0, 3-6:1, 6-9:2, 9-12:3, 12이상:4
unique_expected_timeline = df_train['expected_timeline'].unique()
# 대체할 값들
replacement_values = {
'less than 3 months': '0-3 months',
'3 months ~ 6 months': '3-6 months',
'6 months ~ 9 months': '6-9 months',
'9 months ~ 1 year': '9 months - 1 year',
'more than a year': 'more than 1 year'
}
# 비슷한 문구를 찾고 해당하는 값으로 대체하는 함수 정의
def replace_similar_values(text):
if isinstance(text, str):
# 대소문자 및 공백을 무시하고 대체할 값 찾기
for pattern, replacement in replacement_values.items():
if re.search(re.compile(re.escape(pattern), re.IGNORECASE), text):
return replacement
# 대체할 값이 없는 경우 'etc'로 분류
return 'etc'
else:
return 'etc' # NaN 또는 기타 형태의 값인 경우 'etc'로 분류
import re
# df_train DataFrame에서 expected_timeline 열의 모든 값을 문자열로 변환
df_train['expected_timeline'] = df_train['expected_timeline'].astype(str)
# expected_timeline 열의 모든 값을 변경
df_train['expected_timeline'] = df_train['expected_timeline'].apply(replace_similar_values)
print(df_train)
# 0223 1차 전처리 후 레이블 인코딩할 칼럼들
real_columns = [
"bant_submit",
"business_unit",
"com_reg_ver_win_rate",
"customer_type",
"enterprise",
"historical_existing_cnt",
"id_strategic_ver",
"it_strategic_ver",
"lead_desc_length",
"inquiry_type",
"product_category",
"expected_timeline",
"ver_cus",
"ver_pro",
"ver_win_rate_x",
"ver_win_ratio_per_bu",
"business_area",
"response_corporate",
"lead_owner",
"is_converted"
]
from sklearn.ensemble import RandomForestClassifier
model2 = RandomForestClassifier()
model2.fit(x_train.fillna(0), y_train)
pred2 = model2.predict(x_val.fillna(0))
get_clf_eval(y_val, pred2)