<jupyter_start><jupyter_text>データ読み込み<jupyter_code>import pandas as pd
import numpy as np

# https://www.kaggle.com/c/titanic/data より
train = pd.read_csv("./data/titanic/train.csv")
test = pd.read_csv("./data/titanic/test.csv")<jupyter_output><empty_output><jupyter_text>データ確認<jupyter_code>train.info()
print("-------------------------------------------")
print(train.isnull().sum())
print("-------------------------------------------")
print(test.isnull().sum())
print("-------------------------------------------")
train.head()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 891 entries, 0 to 890
Data columns (total 12 columns):
PassengerId    891 non-null int64
Survived       891 non-null int64
Pclass         891 non-null int64
Name           891 non-null object
Sex            891 non-null object
Age            714 non-null float64
SibSp          891 non-null int64
Parch          891 non-null int64
Ticket         891 non-null object
Fare           891 non-null float64
Cabin          204 non-null object
Embarked       889 non-null object
dtypes: float64(2), int64(5), object(5)
memory usage: 83.6+ KB
-------------------------------------------
PassengerId      0
Survived         0
Pclass           0
Name             0
Sex              0
Age            177
SibSp            0
Parch            0
Ticket           0
Fare             0
Cabin          687
Embarked         2
dtype: int64
-------------------------------------------
PassengerId      0
Pclass           0
Name             0
Sex              0
Age       [...]<jupyter_text>男女別人数<jupyter_code>sns.countplot(x='Sex', data = train)<jupyter_output><empty_output><jupyter_text>男女別生存率<jupyter_code>%matplotlib inline 
import matplotlib.pyplot as plt
import seaborn as sns
g = sns.factorplot(x="Sex", y="Survived",  data=train,
                   size=4, kind="bar", palette="muted")
g.despine(left=True)
g = g.set_ylabels("survival probability")<jupyter_output>/anaconda3/lib/python3.7/site-packages/seaborn/categorical.py:3666: UserWarning: The `factorplot` function has been renamed to `catplot`. The original name will be removed in a future release. Please update your code. Note that the default `kind` in `factorplot` (`'point'`) has changed `'strip'` in `catplot`.
  warnings.warn(msg)
/anaconda3/lib/python3.7/site-packages/seaborn/categorical.py:3672: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)<jupyter_text>PClass別人数<jupyter_code>sns.countplot(x='Pclass', data = train)<jupyter_output><empty_output><jupyter_text>PClass別生存率<jupyter_code>%matplotlib inline 
import matplotlib.pyplot as plt
import seaborn as sns
g = sns.factorplot(x="Pclass", y="Survived",  data=train,
                   size=4, kind="bar", palette="muted")
g.despine(left=True)
g = g.set_ylabels("survival probability")<jupyter_output>/anaconda3/lib/python3.7/site-packages/seaborn/categorical.py:3666: UserWarning: The `factorplot` function has been renamed to `catplot`. The original name will be removed in a future release. Please update your code. Note that the default `kind` in `factorplot` (`'point'`) has changed `'strip'` in `catplot`.
  warnings.warn(msg)
/anaconda3/lib/python3.7/site-packages/seaborn/categorical.py:3672: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
/anaconda3/lib/python3.7/site-packages/scipy/stats/stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval<jupyter_text>生存率に対する相関<jupyter_code>train2 = train.copy()

# 欠損値を中央値で埋める
train2.Age = train.Age.fillna(train.Age.median())
# 0, 1に変換
train2.Sex = train.Sex.replace(['male', 'female'], [0, 1])
del train2['PassengerId']
del train2['Name']
del train2['Ticket']
del train2['Cabin']
del train2['Embarked']


colormap = plt.cm.viridis
plt.figure(figsize=(12,12))
plt.title('Pearson Correlation of Features', y=1.05, size=15)

sns.heatmap(train2.astype(float).corr(),linewidths=0.1,vmax=1.0, square=True, cmap=colormap, linecolor='white', annot=True)

plt.figure()
sns.FacetGrid(data=train, hue="Survived", aspect=4).map(sns.kdeplot, "Age", shade=True)
plt.ylabel('Passenger Density')
plt.title('KDE of Age against Survival')
plt.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16684913509962776, 'fraction_numerical': 0.033939128530764175, 'mean_word_length': 3.2611940298507465, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '450496', 'license': 'MIT', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1578, 'n_words': 367, 'path': 'titanic_visualize.ipynb', 'repo_name': 'ninomae-makoto/kaggle', 'size': '4567'}