text_plain_output_1.png
from sklearn.tree import DecisionTreeRegressor

import os

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

import seaborn as sns

import numpy as np
import pandas as pd
import seaborn as sns
import os
train_data = pd.read_csv('../input/train.csv')
test_data = pd.read_csv('../input/test.csv')

Survials_By_Age = train_data.groupby('Age')['Survived'].sum().reset_index()
Survials_By_Age_Segment = []
age_difference = 5
max_age = 70
for i in range(max_age // age_difference):
    s = 0
    for j in range(age_difference):
        s = s + Survials_By_Age.loc[[i * age_difference + j, 'Age'], 'Survived'][0]
    Survials_By_Age_Segment.append(s)
Survials_By_Age_Segment = pd.Series(Survials_By_Age_Segment, index=list(range(0, max_age, age_difference)))

from sklearn.tree import DecisionTreeRegressor
titanic_model = DecisionTreeRegressor(random_state=1)
X = pd.DataFrame(train_data['Age'].fillna(0))
y = train_data['Survived']
titanic_model.fit(X, y)
X_test = pd.DataFrame(test_data['Age'].fillna(0))
prediction = titanic_model.predict(X_test)
L = []
for i in range(len(prediction)):
    if prediction[i] > 0.5:
        L.append(1)
    else:
        L.append(0)
L = pd.DataFrame({'PassengerId': test_data['PassengerId'], 'Survived': L})

L.to_csv('Test_1.csv')
print(L)