결과 시각화하기
커스텀 손실 함수를 사용해 모델을 학습시켰으니, 이제 성능을 확인해 보겠습니다. sklearn의 r2_score() 함수로 R\(^2\) 값을 다시 확인하고, plt.scatter()로 예측값과 실제값의 산점도를 그릴 거예요. 흥미로운 결과가 나올 겁니다!
이 연습은 강의의 일부입니다
Python으로 배우는 금융 분야 Machine Learning
연습 안내
.predict(),model_2,scaled_test_features를 사용해 테스트 세트에 대한 예측을 생성하세요.test_preds와test_targets를 사용해 테스트 세트 예측의 R\(^2\) 점수를 평가하세요.plt.scatter()로 테스트 세트의 타깃과 실제 값을 산점도로 그리고, 레이블을'test'로 지정하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Evaluate R^2 scores
train_preds = model_2.predict(scaled_train_features)
test_preds = ____
print(r2_score(train_targets, train_preds))
print(____)
# Scatter the predictions vs actual -- this one is interesting!
plt.scatter(train_preds, train_targets, label='train')
plt.scatter(____) # plot test set
plt.legend(); plt.show()