모의고사 1유형
모의고사 1회 입니다
아래 코드에 틀린건 없을까요?
최종적으로 제출할때 print는 여기에 1개만 있어야하는거죠?
print(roc_auc_score(y_val, pred[:,1])) 평가지표에 print 하면 안되는거맞죵? 확인부탁드립니다.

#기출1회
import pandas as pd
train = pd.read_csv("data/customer_train.csv")
test = pd.read_csv("data/customer_test.csv")
#***********************데이터확인
# print(train.shape, test.shape)
# print(train.head()) #target=성별
# print(test.head())
#문자형2개
# print(train.info())
#결측치 있음
# print(train.isnull().sum())
# 환불금액 2295
# print(test.isnull().sum())
# 환불금액 1611
#***********************전처리 *결합it인
#결측치제거/있음
train['환불금액']=train['환불금액'].fillna(0)
test['환불금액']=test['환불금액'].fillna(0)
#train합치기/없음
# pd.concat([X_train, y_train['성별']],axis=1)
#id없애기/있음
train= train.drop('회원ID',axis=1)
test_id= test.pop('회원ID')
#t타켓
target=train.pop('성별')
#인코딩
from sklearn.preprocessing import LabelEncoder
# from sklearn import preprocessing
# print(dir(preprocessing))
# print(help(preprocessing.LabelEncoder))
cols= train.select_dtypes(include='object').columns
for col in cols :
le= LabelEncoder()
train[col] = le.fit_transform(train[col])
test[col] = le.transform(test[col])
#***********************분리
from sklearn.model_selection import train_test_split
from sklearn import model_selection
# print(dir(model_selection))
# print(help(model_selection.train_test_split))
X_tr, X_val, y_tr, y_val = train_test_split(
train,
target,
test_size=0.2,
random_state=2022
)
#***********************모델
from sklearn.ensemble import RandomForestClassifier
# model= RandomForestClassifier(random_state=0)
model= RandomForestClassifier(random_state=0, max_depth=7, n_estimators=1000)
model.fit(X_tr, y_tr)
pred= model.predict_proba(X_val)
#***********************평가
from sklearn.metrics import roc_auc_score
# from sklearn import metrics
# print(dir(metrics))
# print(help(metrics.roc_auc_score))
print(roc_auc_score(y_val, pred[:,1]))
# 0.6186558526810393 (random_state=0)
# 0.6641618297401879 (random_state=0, max_depth=7, n_estimators=1000)
#***********************예측
pred= model.predict_proba(test)[:,1]
result= pd.DataFrame({
'pred':pred
})
#***********************저장
result.to_csv('result.csv', index=False)
print(pd.read_csv('result.csv'))
답변 1
강의 연장 문의
0
3
1
수강 신청 연장 문의드립니다.
0
15
1
작업형 1번문제... 환경관련
0
24
2
12회 기출은 언제 업데이트 될까요??
0
34
2
8/6 작성한 연장문의 질문글에 대한 재요청
0
36
2
수강기간 연장 문의
0
33
2
수강기간 연장문의
0
35
2
수강기간 연장 요청 문의드립니다
0
34
2
수강 기간 연장 문의
0
44
2
수강연장 가능 문의 (기간 약 한달반)
0
57
2
수강기간 연장 가능할까요 선생님
0
72
2
Section15. 수업에 사용하는 데이터 주소가 다 보이지 않아서 실습을 위한 데이터를 다운 받지 못하고 있습니다.
0
49
3
수강연장요청 문의
0
84
2
아무래도 다음 시험 연장은 어렵겠죠?
0
104
2
빅분기 12회 결과 관련 문의
0
110
1
책이랑 강의랑 순서나 예제가 다른것 같네요
0
79
2
수강연장 문의
0
102
2
재검토 요청 방법 좀 알려주셔요...-.-;;
0
102
2
12회 실기 질문(작업형 2)
0
89
2
뒤로가기 버튼 같은 것이 있나요?
0
63
1
강의 연장 문의
0
97
2
출력값 질문
0
69
2
수업노트가 어디에 있나요?
0
61
1
실기시험 제출관련
0
224
3





