예시문제 작업형2 코드 질문
import pandas as pd
test = pd.read_csv("data/X_test.csv")
train = pd.read_csv("data/X_train.csv")
y_train = pd.read_csv("data/y_train.csv")
pd.set_option('display.max_columns', None)
# 사용자 코딩
test['환불금액'] = test['환불금액'].fillna(0)
train['환불금액'] = train['환불금액'].fillna(0)
from sklearn.preprocessing import LabelEncoder
cols = train.select_dtypes(include='object').columns
# print(cols)
le = LabelEncoder()
for col in cols:
train[col] = le.fit_transform(train[col])
test[col] = le.transform(test[col])
train = train.drop('cust_id', axis = 1)
test_id = test.pop('cust_id')
# print(train.head())
# print(train.head(3))
from sklearn.model_selection import train_test_split
X_tr, X_val, y_tr, y_val = train_test_split(train, y_train['gender'], test_size=0.2, random_state = 0)
from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(random_state = 0)
rf.fit(X_tr, y_tr)
pred = rf.predict_proba(X_val)
# print(pred)
from sklearn.metrics import roc_auc_score
# print(roc_auc_score(y_val, pred[:, 1]))
pred_res = rf.predict_proba(test)
pd.DataFrame({'custid': test_id, 'gender': pred_res[:,1]}).to_csv('950326.csv', index=False)
# print(pd.read_csv('950326.csv'))안녕하세요, 딴짓님
제가 강의 안 보고 혼자 작성한 내용인데요..
혹시 해당 내용처럼 작성하면 올바르게 작성한 건지 혼자서 판단이 안 돼서요ㅠ
RandomForest 모델 + 소개해주신 lightGBM정도만 준비해가면 될는지요..
답변 1
0
네 큰 문제 없어 보입니다. 💪💪💪💪💪
6회를 준비할 땐 마지막 csv는 아래와 같은 형태가 될 예정이에요
pd.DataFrame({'pred': pred_res[:,1]}).to_csv('result.csv', index=False)그리고 데이터셋이 2개가 주어진 적이 많으니
train = pd.concat([train, y_train['gender']], axis=1) 이렇게 합쳐서도 연습해주세요 :)
수업노트가 어디에 있나요?
0
17
1
실기시험 제출관련
0
150
2
6.20 작업형 2 과적합
0
157
3
코딩팡 장업형2 베이스 라인 인코딩 종류 질문
0
48
2
로지스틱회귀, 회귀
0
47
2
회귀 문제를 풀때 질문입니다.
0
54
1
불균형 처리 후 성능이 더 낮아졌다면,
0
61
2
실기 체험 제2유형 에러 문의
0
61
1
LIGHTGBM 으로 하면 pred값이 소수점 6자리까지 나오는게 맞나요
0
49
2
3번문제 등분산 가정
0
47
2
작업형3 target 형 변환 질문
0
34
2
[작업형1] 연습문제 섹션1 ~ 10 의 section4
0
36
3
원핫인코딩과 레이블 인코딩에서 concat
0
58
2
제2유형 질문입니다.
0
46
2
C()
0
44
2
작업형 2에서 strafity 적용 유무
0
51
2
수강 기간 연장 가능 여부 문의드립니다.
0
60
1
ols
0
43
2
2유형 작성관련 질문(일반 심화)
0
39
2
2유형 작성관련 질문
0
41
2
2유형 object컬럼 개수 다르면
0
48
2
코딩팡질문이요ㅠㅠ
0
45
2
관찰값과 기대값의 개념이 헷갈립니다.
0
25
2
작업형2 ID 컬럼 삭제 질문
0
45
2





