우리가 만든 정답이 곡선형이기 때문에 직선인 model_one은 성능이 별로입니다. model_two는 곡선을 완벽하게 표현했습니다. model_three는 훈련할 때는 환상적으로 작동하는 것처럼 보입니다. model_three는 model_two와 거의 겹칩니다. 그러나 문제는 테스트할 때 발생합니다. ftr = -1 부근에서 예측 값이 폭발적으로 증가합니다. 비교를 위해 모델들을 다시 실행하고 그 결과를 테이블로 정리합니다. 모델을 쉽게 추가할 수 있기 때문에 6차 다항식 모델도 비교 대상에 넣겠습니다.
In [10]:
results = [] for complexity in [1, 2, 6, 9]: model = np.poly1d(np.polyfit(train_ftr, train_tgt, complexity)) train_error = np.sqrt(mse(train_tgt, model(train_ftr))) test_error = np.sqrt(mse(test_tgt, model(test_ftr))) results.append((complexity, train_error, test_error)) columns = ["Complexity", "Train Error", "Test Error"] results_df = pd.DataFrame.from_records(results, columns=columns, index="Complexity") results_df
Out [10]:
Complexity |
Train Error |
Test Error |
1 |
45.4951 |
86.6915 |
2 |
1.0828 |
1.2766 |
6 |
0.2819 |
6.1417 |
9 |
0.0000 |
317.3634 |