<jupyter_start><jupyter_text>Titanic Submission to Kaggle (Part 1) Part of my Tutorial series to Kaggle.This is my first solution to the Titanic competition. I use this code for the tutorial series I am writing on Medium at LINK.<jupyter_code># importing the basic libs

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
% matplotlib inline

# loading the data

data = pd.read_csv("train.csv")
data.info()
# dropping the `Cabin` and `Ticket` columns.
data.drop(('Cabin'), axis=1, inplace=True)

# filling in the age missing entries with avg.
data['Age'].fillna(data['Age'].mean(), inplace=True)

# dropping the rest of the missing data.
data.dropna(inplace=True)
# creating the feature matrix (with numerical features) and label vector
X = data.drop(['PassengerId','Survived', 'Name', 'Sex', 'Embarked', 'Ticket'], axis=1)
y = data.ix[:, 'Survived']
# import the decision tree classifier and the cross-validation package.
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import cross_val_score

# create the first model and assess its accuracy.
clf = DecisionTreeClassifier()
cross_val_score(clf, X, y, cv=10).mean()
# import the test data and have a look at it.
data_test = pd.read_csv("test.csv")
data_test.info()
# fill in the missing values in the 2 features we will use ('Age', 'Fare').
data_test['Age'].fillna(data['Age'].mean(), inplace=True)
data_test['Fare'].fillna(data['Fare'].mean(), inplace=True)

# create the feature vector.
X_test = data_test.drop(['PassengerId', 'Name', 'Sex', 'Embarked', 'Ticket', 'Cabin'], axis=1)

# fit the model to the train data.
clf = DecisionTreeClassifier().fit(X, y)

# predict the labels for the test data
predicted = pd.Series(clf.predict(X_test))

# create a dataframe to store the prediction in the format Kaggle needs for submission.
solution = pd.concat([data_test['PassengerId'], predicted], axis=1)
solution.columns = ['PassengerId','Survived']

# output the results in a csv
solution.to_csv('submission.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12414800389483933, 'fraction_numerical': 0.0038948393378773127, 'mean_word_length': 5.715686274509804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '77608', 'license': 'MIT', 'n_tokens_mistral': 677, 'n_tokens_neox': 652, 'n_words': 228, 'path': 'Titanic/.ipynb_checkpoints/Titanic Submission to Kaggle (Part 1)-checkpoint.ipynb', 'repo_name': 'adamjermann/data-science-tutorial', 'size': '2054'}