๊ณผ์ ํฉ ํด๊ฒฐ: ํ ์คํธ ๋ฐ์ดํฐ ๋ถ๋ฆฌ ์ค์ตยถ
- x๋ณ์: Fare, Sex
- y๋ณ์: Survived
Inย [ย ]:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import sklearn
Inย [ย ]:
# ํ์ดํ๋ ๋ฐ์ดํฐ
titanic = pd.read_csv('C:/Users/LOVE/Downloads/vscode/ML/titanic/train.csv')
titanic.head(3)
Out[ย ]:
PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0 | 3 | Braund, Mr. Owen Harris | male | 22.0 | 1 | 0 | A/5 21171 | 7.2500 | NaN | S |
1 | 2 | 1 | 1 | Cumings, Mrs. John Bradley (Florence Briggs Th... | female | 38.0 | 1 | 0 | PC 17599 | 71.2833 | C85 | C |
2 | 3 | 1 | 3 | Heikkinen, Miss. Laina | female | 26.0 | 0 | 0 | STON/O2. 3101282 | 7.9250 | NaN | S |
Inย [ย ]:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(titanic[['Fare', 'Sex']], titanic[['Survived']],
test_size = 0.3, shuffle = True, random_state = 42,
stratify = titanic[['Survived']])
Inย [ย ]:
print(X_train.shape, X_test.shape, y_train.shape, y_test.shape)
(623, 2) (268, 2) (623, 1) (268, 1)
Inย [ย ]:
# ์๋ณธ ๋ฐ์ดํฐ์ ๋ํ Y ๊ฐ์ ๋ถํฌ
sns.countplot(titanic, x = 'Survived')
Out[ย ]:
<Axes: xlabel='Survived', ylabel='count'>
Inย [ย ]:
sns.countplot(y_train, x = 'Survived')
Out[ย ]:
<Axes: xlabel='Survived', ylabel='count'>
Inย [ย ]:
sns.countplot(y_test, x = 'Survived')
Out[ย ]:
<Axes: xlabel='Survived', ylabel='count'>
'๐ Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ์ด์ฌ ํ๊ท ๋ถ๋ฅ ๋ชจ๋ธ๋ง ์ค์ต (0) | 2024.02.06 |
---|---|
ํ์ด์ฌ ๋ฐ์ดํฐ ๋ถ์ ํ๋ก์ธ์ค ์ค์ต w. ํ์ดํ๋ (0) | 2024.02.05 |
ํ์ด์ฌ ์ค์ผ์ผ๋ง ์ค์ต (0) | 2024.02.05 |
ํ์ด์ฌ ์ธ์ฝ๋ฉ ์ค์ต (0) | 2024.02.05 |
ํ์ด์ฌ ๊ฒฐ์ธก์น ํ์ธ ์ค์ต (0) | 2024.02.05 |