추론: 여기에서 고양이 그림의 도움으로 항공편 가격과 항공사 사이의 상자 그림을 그리려고 하고 다음과 같은 결론을 내릴 수 있습니다. Jet Airways는 가격면에서 가장 이상치를 가지고 있습니다..
추론: 이제 고양이 플롯의 도움으로 항공편 가격과 출발지 사이에 상자 플롯을 플로팅합니다. 승객이 목적지로 여행하는 장소이며 출발지인 Banglore가 가장 이상값을 가지고 있는 반면 Chennai가 가장 적은 이상값을 가지고 있음을 알 수 있습니다.
추론: 여기서 우리는 항공편 가격과 승객이 여행하는 목적지 사이의 고양이 플롯의 도움으로 상자 플롯을 플롯하고 다음을 알아냈습니다. 뉴델리에 가장 많은 특이치가 있고 콜카타가 가장 적습니다.
먼저 처리된 데이터를 보자
train_df.head()
출력:
여기에서 먼저 기능과 레이블을 나눈 다음 시간을 분 단위로 변환합니다.
train_df['지속 시간'] = train_df['지속 시간'].str.replace("h", '*60').str.replace(' ','+').str.replace('m','* 1').apply(평가) test_df['기간'] = test_df['기간'].str.replace("h", '*60').str.replace(' ','+').str. replace('','*1').apply(평가)
여행 날짜: 여기에서는 모델 단계에서 더 나은 사전 처리를 위해 데이터 세트의 여행 날짜 형식을 구성하고 있습니다.
기차_df["여행_일"] = 기차_df['날짜_오브_여행'].str.split('/').str[0].astype(int) 기차_df["여행_월"] = 기차_df['날짜_of_여행'].str.split( '/').str[1].astype(int) train_df.drop(["Date_of_Journey"], 축 = 1, inplace = True)
출발 시간: 여기에서 출발 시간을 시간과 분으로 변환하고 있습니다.
train_df["Dep_hour"] = pd.to_datetime(train_df["Dep_Time"]).dt.hour train_df["Dep_min"] = pd.to_datetime(train_df["Dep_Time"]).dt.분 train_df.drop([" Dep_Time"], 축 = 1, inplace = True)
도착 시간: 마찬가지로 우리는 도착 시간을 시간과 분으로 변환하고 있습니다.
train_df["Arrival_hour"] = pd.to_datetime(train_df.Arrival_Time).dt.hour train_df["Arrival_min"] = pd.to_datetime(train_df.Arrival_Time).dt.minute train_df.drop(["도착_시간"], 축 = 1, 제자리 = 참)
이제 최종 전처리 후 데이터세트를 살펴보겠습니다.
train_df.head()
출력:
월(기간) 대 항공편 수에 대한 막대 차트 그리기
plt.Figure(figsize = (10, 5)) plt.title('월별 비행 횟수') ax=sns.countplot(x = 'Journey_month', 데이터 = train_df) plt.xlabel('Month') plt. ax.patches에서 p에 대한 ylabel('비행 횟수'): ax.annotate(int(p.get_height()), (p.get_x()+0.25, p.get_height()+1), va='bottom ', 색상 = '검정')
출력:
추론: 여기 위의 그래프에서 우리는 한 달 동안의 여행과 여러 항공편에 대한 카운트 플롯을 플로팅했으며 다음을 확인했습니다. XNUMX월은 가장 많은 항공편이 있습니다.
항공사 유형 대 항공편 수에 대한 플로팅 막대 차트
plt.Figure(figsize = (20,5)) plt.title('항공사별 항공편 수') ax=sns.countplot(x = '항공사', 데이터 =train_df) plt.xlabel('항공사') plt .ylabel('비행 횟수') plt.xticks(회전 = 45) for p in ax.patches: ax.annotate(int(p.get_height()), (p.get_x()+0.25, p.get_height( )+1), va='하단', 색상= '검정색')
출력:
추론: 이제 위의 그래프에서 항공사 유형과 항공편 수를 보면 Jet Airways가 가장 많이 탑승한 항공편을 볼 수 있습니다.
항공권 가격과 항공사 비교하기
plt.Figure(figsize = (15,4)) plt.title('가격 VS 항공사') plt.scatter(train_df['항공사'], train_df['가격']) plt.xticks plt.xlabel('항공사' ) plt.ylabel('티켓 가격') plt.xticks(회전 = 90)
출력:
모든 기능 간의 상관관계
플로팅 상관관계
plt.Figure(figsize = (15,15)) sns.heatmap(train_df.corr(), annot = True, cmap = "RdYlGn") plt.show()
출력:
아무 소용이 없으므로 Price 열 삭제
데이터 = train_df.drop(["가격"], 축=1)
범주형 데이터와 수치 데이터 다루기
train_categorical_data = data.select_dtypes(exclude=['int64', 'float','int32']) train_numerical_data = data.select_dtypes(include=['int64', 'float','int32']) test_categorical_data = test_df.select_dtypes( exclude=['int64', 'float','int32','int32']) test_numerical_data = test_df.select_dtypes(include=['int64', 'float','int32']) train_categorical_data.head()
출력:
범주형 열에 대한 레이블 인코딩 및 핫 인코딩
le = LabelEncoder() train_categorical_data = train_categorical_data.apply(LabelEncoder().fit_transform) test_categorical_data = test_categorical_data.apply(LabelEncoder().fit_transform) train_categorical_data.head()
출력:
범주형 데이터와 숫자형 데이터 모두 연결
X = pd.concat([train_categorical_data, train_numerical_data], axis=1) y = train_df['가격'] test_set = pd.concat([test_categorical_data, test_numerical_data], axis=1) X.head()
출력:
y.head ()
출력:
0 3897 1 7662 2 13882 3 6218 4 13302 이름: 가격, dtype: int64
결론
출처: https://www.analyticsvidhya.com/blog/2022/01/flight-fare-prediction-using-machine-learning/