<jupyter_start><jupyter_text>목표다음 아래의 모델을 이용하여 4월 동안의 관광객 예측을 한다.A, B, C, D, E (범위 구분하기)**사용한 모델**- Logisic Regression  Data 전처리  데이터 불러오기<jupyter_code>import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
timeseries_data = pd.read_excel('seoul_merge_clean_monthly_yesapril.xlsx')
# test_data = pd.read_excel('seoul_merge_clean_monthly_yesapril.xlsx')
# 3월까지의 데이터
timeseries_data = timeseries_data.dropna(axis=0)
timeseries_data.head()<jupyter_output><empty_output><jupyter_text>명목형 변수를 Dummay Variable로 변경> 이유 : 회귀식에 input은 반드시 : 수치형 데이터 (명목형 변수 -> 수치형 변수)>> 항목 : - 'Day'- 'dust'- 'event_total'- 'warninglevel'<jupyter_code>dummies_Day = pd.get_dummies(timeseries_data['Day'])
dummies_dust = pd.get_dummies(timeseries_data['dust'])
dummies_warninglevel = pd.get_dummies(timeseries_data['warninglevel'])
dummies_season = pd.get_dummies(timeseries_data['season'])
timeseries_data = timeseries_data.join(dummies_Day.add_prefix('Day_'))
timeseries_data = timeseries_data.join(dummies_dust.add_prefix('dust_'))
timeseries_data = timeseries_data.join(dummies_warninglevel.add_prefix('warninglevel_'))
timeseries_data = timeseries_data.join(dummies_season.add_prefix('season_'))
re_columnlist = ['Day_월', 'Day_화', 'Day_수', 'Day_목', 'Day_금', 'Day_토', 'Day_일'
             ,'dust_초미세먼지', 'dust_미세먼지', 'dust_둘 다 있음', 'dust_좋음'
             ,'warninglevel_경보', 'warninglevel_주의보', 'warninglevel_없음'
             ,'season_봄', 'season_여름', 'season_가을', 'season_겨울'
             ,'event_total'
             ,'rain_mean', 'temper_mean', 'daily_predict'
             ,'ST_level']
timeseries_data = timeseries_data[re_columnlist]
timeseries_data.head()<jupyter_output><empty_output><jupyter_text>Train/Test Set 7:3으로 나누기<jupyter_code>train_test_timeseries_data = timeseries_data[timeseries_data.index < 3742]
month4_timeseries_data = timeseries_data[timeseries_data.index >= 3742]
X = train_test_timeseries_data[['Day_월', 'Day_화', 'Day_수', 'Day_목', 'Day_금', 'Day_토', 'Day_일'
             ,'dust_초미세먼지', 'dust_미세먼지', 'dust_둘 다 있음', 'dust_좋음'
             ,'warninglevel_경보', 'warninglevel_주의보', 'warninglevel_없음'
             ,'season_봄', 'season_여름', 'season_가을', 'season_겨울'
             ,'event_total'
             ,'rain_mean', 'temper_mean', 'daily_predict']]
Y = train_test_timeseries_data['ST_level']
X_train, X_test, Y_train, Y_test = train_test_split(X.values, Y.values, test_size=0.30)
print('X_train의 크기',np.shape(X_train))
print('Y_train의 크기',np.shape(Y_train))
print('X_test의 크기',np.shape(X_test))
print('Y_test의 크기',np.shape(Y_test))<jupyter_output>X_train의 크기 (2618, 22)
Y_train의 크기 (2618,)
X_test의 크기 (1123, 22)
Y_test의 크기 (1123,)<jupyter_text>Logist Regression 모델 설계<jupyter_code>from sklearn.linear_model import LogisticRegression
LRC = LogisticRegression()
LRC.fit(X_train, Y_train)<jupyter_output>C:\Users\lhj91\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
C:\Users\lhj91\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:469: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)<jupyter_text>모델 평가(Logistic Regression)<jupyter_code>predicted = LRC.predict(X_test)
accuracy = LRC.score(X_test, Y_test)
print("Logistic Regression test file accuracy:" + str(accuracy))<jupyter_output>Logistic Regression test file accuracy:0.7693677649154052<jupyter_text>4월 데이터 예측<jupyter_code>month4_X = month4_timeseries_data[['Day_월', 'Day_화', 'Day_수', 'Day_목', 'Day_금', 'Day_토', 'Day_일'
                     ,'dust_초미세먼지', 'dust_미세먼지', 'dust_둘 다 있음', 'dust_좋음'
                     ,'warninglevel_경보', 'warninglevel_주의보', 'warninglevel_없음'
                     ,'season_봄', 'season_여름', 'season_가을', 'season_겨울'
                     ,'event_total'
                     ,'rain_mean', 'temper_mean', 'daily_predict']]

month4_Y = month4_timeseries_data['ST_level']
predicted = LRC.predict(month4_X)

accuracy = LRC.score(month4_X, month4_Y)
print("Logistic Regression test file accuracy:" + str(accuracy))<jupyter_output>Logistic Regression test file accuracy:0.6666666666666666
{'fraction_non_alphanumeric': 0.13053667682212328, 'fraction_numerical': 0.022732599015701897, 'mean_word_length': 5.658346333853354, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '633681', 'license': 'MIT', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1975, 'n_words': 277, 'path': 'logistic_regression/DataAnalysis.ipynb', 'repo_name': 'hanakim120/-grandpark-seoul-data-mining', 'size': '4267'}