2์ ํ์ ๊ทธ๋ฅ ๊ทธ๋๋ก ๋ฐ๋ผํ๊ธฐ๋ง ํ๋ฉด ๋๋ค ๊ทธ๋ฅ ๋ฐฉ์์ ์๊ธฐํ์
์๋์ ๋ด์ฉ์ ์ ๋ณด๊ณ ๊ทธ๋ฅ ์๊ฐ๋๋ ๊ณผ์ ์ ์ญ ์จ๋ดค๋ค ์ด ๊ณผ์ ์ด ์๊ฐ ๋๋ค๋ฉด 2์ ํ์ ํธ๋๋ฐ ๋ฌธ์ ์๋ค
- ๋ฐ์ดํฐ๋ฅผ x_train, x_test, y_train์ผ๋ก ๋ถ๋ฆฌํ๋ค
- x_train, x_test, y_train์ shape ํ์ธ โ ํ,์ด ๊ฐ์ ํ์ธ โx_train๊ณผ x_test์ ์นผ๋ผ ๊ฐ์๊ฐ ์ผ์นํ์ง ํ์ธ
- x_train, x_test, y_train์ info ํ์ธ โ ๋ฐ์ดํฐ ํ์ ํ์ธ โ object, category ์์ ๊ฒฝ์ฐ ์ํซ ์ธ์ฝ๋ฉ
- x_train, x_test, y_train์ head ํ์ธ โ ๋ฐ์ดํฐ ์ด๋ป๊ฒ ์๊ฒผ๋์ง ํ๋ฒ ์ง์ ๋ณธ๋ค
- x_train, x_test, y_train์ describe ํ์ธ โ x_train, x_test์ ๊ธฐ์ดํต๊ณ๋ ํ์ธ โ min, max๊ฐ ํฌ๊ฒ ์ฐจ์ด๋๋์ง ์ด์์น ํ์ธ
- x_train, x_test, y_train์ is.null().sum() ํ์ธ โ๊ฒฐ์ธก์น ์๋์ง ํ์ธ
- x_train, x_test ์ ID ์ ๊ฑฐ โ ID=x_test['ID'].copy() ํ๊ณ x_train๊ณผ x_test์ ID ๋ฅผ drop
- x_train, x_test ์ํซ ์ธ์ฝ๋ฉ ์ ์ฉ โ x_train=pd.get_dummies(x_train) โ x_train.info() โ ์ํซ ์ธ์ฝ๋ฉ ํ์ ์นผ๋ผ ๊ฐ์์ ์์๊ฐ ์ผ์นํ์ง ๊ผญ ํ์ธ
- x_train, y_train ๋ฐ์ดํฐ ๋ถ๋ฆฌ โ from sklearn.model_selection import train_test_split ์ผ๋ก ๋ฐ์ดํฐ ๋ถ๋ฆฌ ***๋ถ๋ฅ๋ถ์์ผ๊ฒฝ์ฐ, ๋ฐ์ดํฐ ๋ถ๋ฆฌํ ๋ stratify = y_train ์ธตํ ์ต์ ๊ผญ ๋ฃ์ด์ค์ผํจ***
- x_train,y_trian ๋ฐ์ดํฐ ํ๋ จ โ from sklearn.ensemble import RandomForestClassifer
- ์์ธก ๋ฐ์ดํฐ ๋ง๋ค๊ธฐ โ y_pred=model.predict(x_val)
- ์ฃผ์ด์ง ํ๊ฐ์งํ๋ก y_val, y_pred ๋ฃ์ด์ ๊ตฌํด๋ณด๊ธฐ โ from sklearn.metrics import f1_score
- x_test๋ฅผ ๋ฃ์ด์ ๊ฒฐ๊ณผ๊ฐ ๋ง๋ค๊ธฐ โ y_result=model.predict(x_test)
- ์ ์ถํ DataFrame ๋ง๋ค๊ธฐ โ result=pd.DataFrame({'ID':ID,'Target':y_result})
- csv๋ก ์ ์ถํ๊ธฐ โ result.to_csv('datafox.csv',index=False)
- ๋ฐ์ดํฐ ๋ถ๋ฌ์ ํ์ธํด๋ณด๊ธฐ โdf2= pd.read_csv("datafox.csv") โ print(df2.head(10))
6ํ์์ ์ค์ํ๊ฑด
๋ถ๋ฅ๋ถ์ ํ์๋ y๊ฐ์ด ์ด์ง๋ถ๋ฅ๊ฐ ์๋๋ผ์ f1_score ๊ตฌํ ๋ ๊ผญ average='macro'๋ฅผ ๋ฃ์ด์ค์ผ ํจ
y_pred=model.predict(x_val)
from sklearn.metrics import f1_score
f1=f1_score(y_val,y_pred, average='macro')
print(f1)