시작하기무료로 시작하기

파이프라인 사용하기

이제 파이프라인, 즉 로지스틱 회귀와 SMOTE 방법을 결합한 모델을 정의했으니 데이터를 대상으로 실행해 보겠습니다. 파이프라인은 하나의 Machine Learning 모델처럼 다루면 돼요. 데이터 Xy는 이미 정의되어 있고, 파이프라인은 이전 연습 문제에서 만들었습니다. 모델 결과가 궁금하시죠? 바로 시도해 볼까요!

이 연습은 강의의 일부입니다

Python으로 배우는 사기 탐지

강의 보기

연습 안내

  • 데이터 'X'와 'y'를 학습 세트와 테스트 세트로 분할하세요. 데이터의 30%를 테스트 세트로 떼어 두고, random_state는 0으로 설정하세요.
  • 학습 데이터에 파이프라인을 학습시키고, X_test 데이터셋에 대해 pipeline.predict() 함수를 실행해 예측 값을 얻으세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Split your data X and y, into a training and a test set and fit the pipeline onto the training data
X_train, X_test, y_train, y_test = ____

# Fit your pipeline onto your training set and obtain predictions by fitting the model onto the test data 
pipeline.fit(____, ____) 
predicted = pipeline.____(____)

# Obtain the results from the classification report and confusion matrix 
print('Classifcation report:\n', classification_report(y_test, predicted))
conf_mat = confusion_matrix(y_true=y_test, y_pred=predicted)
print('Confusion matrix:\n', conf_mat)
코드 편집 및 실행