> For the complete documentation index, see [llms.txt](https://air-pro.gitbook.io/air-delay-project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://air-pro.gitbook.io/air-delay-project/undefined-3/2.md).

# 2차 모델 테스트

## 모델 선정

학습에 사용된 데이터는 2차 전처리 과정에서 도출된 데이터를 사용하였다.

{% content-ref url="/pages/-LkxefOiaYHjvpswHavG" %}
[2차 전처리 과정](/air-delay-project/undefined-2/undefined-3/2.md)
{% endcontent-ref %}

이번 테스트에서는 초기 모델 테스트에서 가장 높은 성능을 보여주었던 랜덤 포레스트의 하이퍼 파라미터를 변경해보고, 출발 데이터와 도착 데이터를 분류하여 각각의 모델을 생성해 테스트를 실시하였다.

사용한 모델은 다음과 같다.

```python
RandomForestClassifier
```

## 도착 데이터 테스트

### 실행 결과

```
# 1. 도착 데이터 예측
# 
# 1) STT 제거
#               precision    recall  f1-score   support
# 
#            0       0.95      0.98      0.96     89870
#            1       0.41      0.22      0.28      6427
# 
#     accuracy                           0.93     96297
#    macro avg       0.68      0.60      0.62     96297
# weighted avg       0.91      0.93      0.92     96297
# 
# 2) STT 구분
# 
# precision    recall  f1-score   support
# 
#            0       0.95      0.99      0.97     89870
#            1       0.55      0.20      0.29      6427
# 
#     accuracy                           0.94     96297
#    macro avg       0.75      0.59      0.63     96297
# weighted avg       0.92      0.94      0.92     96297
# 
# 3) REG 묶기
# 
# precision    recall  f1-score   support
# 
#            0       0.94      0.98      0.96     89870
#            1       0.43      0.19      0.26      6427
# 
#     accuracy                           0.93     96297
#    macro avg       0.69      0.59      0.61     96297
# weighted avg       0.91      0.93      0.92     96297
```

### 실행 코드

```python
from sklearn.model_selection import StratifiedShuffleSplit
split = StratifiedShuffleSplit(n_splits = 1, test_size = 0.2, random_state=42)
df_x = df_A
for df_index, val_index in split.split(df_x, df_x['SDT_YY']) :
    df1 = df_x.iloc[df_index]
    val1 = df_x.iloc[val_index]
#학습데이터셋 스플릿하기
df_y = df1['DLY']
df_x = df1.drop(['DLY'], axis=1)
#밸리드데이터셋 스플릿하기
val_y = val1['DLY']
val_x = val1.drop(['DLY'], axis=1)

from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report

random_forest = RandomForestClassifier(n_estimators=500)
random_forest.fit(df_x, df_y)
Y_pred = random_forest.predict(val_x)
print(random_forest)
print(classification_report(val_y, Y_pred))
print()
```

## 출발 데이터 테스트

### 실행 결과

```
# 2. 출발데이터 예측
# 
# 1) STT제거
# precision    recall  f1-score   support
# 
#            0       0.86      0.93      0.89     79374
#            1       0.44      0.27      0.33     16923
# 
#     accuracy                           0.81     96297
#    macro avg       0.65      0.60      0.61     96297
# weighted avg       0.78      0.81      0.79     96297
# 
# 2) STT 구분
# precision    recall  f1-score   support
# 
#            0       0.86      0.95      0.90     79374
#            1       0.52      0.26      0.35     16923
# 
#     accuracy                           0.83     96297
#    macro avg       0.69      0.60      0.62     96297
# weighted avg       0.80      0.83      0.80     96297
# 
# 3) REG 묶기
# 
# precision    recall  f1-score   support
# 
#            0       0.86      0.94      0.89     79374
#            1       0.47      0.26      0.34     16923
# 
#     accuracy                           0.82     96297
#    macro avg       0.66      0.60      0.62     96297
# weighted avg       0.79      0.82      0.80     96297
```

### 실행 코드

```python
from sklearn.model_selection import StratifiedShuffleSplit
split = StratifiedShuffleSplit(n_splits = 1, test_size = 0.2, random_state=42)
df_x = df_D
for df_index, val_index in split.split(df_x, df_x['SDT_YY']) :
    df1 = df_x.iloc[df_index]
    val1 = df_x.iloc[val_index]
#학습데이터셋 스플릿하기
df_y = df1['DLY']
df_x = df1.drop(['DLY'], axis=1)
#밸리드데이터셋 스플릿하기
val_y = val1['DLY']
val_x = val1.drop(['DLY'], axis=1)


# In[42]:


from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report

random_forest = RandomForestClassifier(n_estimators=500)
random_forest.fit(df_x, df_y)
Y_pred = random_forest.predict(val_x)
print(random_forest)
print(classification_report(val_y, Y_pred))
print()
```

## 결과 해석 및 회고

전체적으로 1차 테스트에 비해 우수한 결과를 보여주었다.  특히나 눈에 띄는 점은 STT(계획시간)을 분류함으로써 상대적으로 precision 및 recall의 성능 향상을 확인할 수 있었다. 또한 출발 데이터와 도착 데이터의 accuracy가 큰 폭으로 차이가 난다는 점도 눈에 띈다.&#x20;

&#x20;
