application_vnd.jupyter.stderr_output_1.png
from sklearn.feature_extraction import DictVectorizer

from sklearn.model_selection import train_test_split

from sklearn.tree import DecisionTreeClassifier

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

data_train = pd.read_csv('train.csv')
data_test = pd.read_csv('test.csv')

data_x = data_train[['Pclass', 'Age', 'Sex']]
data_y = data_train['Survived']
age_mean = data_x.mean()['Age']
data_x = data_x.fillna(age_mean)
for i in range(1, 4):
    data_x.loc[data_x.Pclass == i, 'Pclass'] = str(i)

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(data_x, data_y, test_size=0.25, random_state=33)
y_train.value_counts()

from sklearn.feature_extraction import DictVectorizer
vec = DictVectorizer(sparse=False)
x_train = vec.fit_transform(x_train.to_dict(orient='record'))
x_test = vec.transform(x_test.to_dict(orient='record'))
vec.get_feature_names()

from sklearn.tree import DecisionTreeClassifier
dtc = DecisionTreeClassifier()
dtc.fit(x_train, y_train)
dtc_y_predict = dtc.predict(x_test)