<jupyter_start><jupyter_text>reading the dataset<jupyter_code>train = pd.read_csv('./dataset/train.csv')
test = pd.read_csv('./dataset/test.csv')

train.shape
test.shape<jupyter_output><empty_output><jupyter_text>Editing Key and Answer Variable<jupyter_code>train = train.set_index(['PassengerId'])
train = train.drop(['Name', 'Ticket', 'Cabin', 'Embarked'], axis=1)
train<jupyter_output><empty_output><jupyter_text>Exploring missing values<jupyter_code>train.isnull().sum()
#test.isnull().sum()

age_median = train['Age'].median()<jupyter_output><empty_output><jupyter_text>fill NA<jupyter_code>train.fillna(age_median, inplace=True)
train.isnull().sum()<jupyter_output><empty_output><jupyter_text>Describe<jupyter_code>train.describe()<jupyter_output><empty_output><jupyter_text>Data Manipulation | Transformation<jupyter_code>treinamento = pd.get_dummies(train)
data_tree = treinamento
treinamento
treinamento=treinamento.drop(['Sex_male'], axis=1)
treinamento = treinamento.rename(columns={'Sex_female': 'Female'})
treinamento = treinamento[['Survived','Fare', 'Female', 'Age','SibSp', 'Parch', 'Pclass']]
treinando = pd.get_dummies(treinamento['Pclass'])
treinamento = treinamento.drop(['Pclass'], axis=1)
treinando = treinando.rename(
    columns={1: 'Pclass_1', 2: 'Pclass_2', 3: 'Pclass_3'})
treinamento = treinamento.join(treinando)
treinamento<jupyter_output><empty_output><jupyter_text>Training<jupyter_code>x_train, x_test, y_train, y_test = train_test_split(treinamento.drop(
    ['Survived'], axis=1), treinamento['Survived'], test_size=0.3, random_state=0)

f'treino: {x_train.shape}, teste: {x_test.shape}'<jupyter_output><empty_output><jupyter_text>Decision Tree Classifier<jupyter_code>from sklearn.tree import DecisionTreeClassifier, export_graphviz
from sklearn.metrics import confusion_matrix, accuracy_score
import graphviz
x_trains, x_tests, y_trains, y_tests = train_test_split(data_tree.drop(
    ['Survived', 'Sex_male'], axis=1), data_tree['Survived'], test_size=0.15, random_state=100)
arvore = DecisionTreeClassifier()
arvore.fit(x_trains, y_trains)
feat_names = ['Pclass', 'Age', 'SibSp', 'Parch', 'Fare', 'Female']
graph_dot = export_graphviz(arvore, class_names=['Morto', 'Vivo'], feature_names=feat_names, out_file=None, filled=True)
g = graphviz.Source(graph_dot, format='pdf')
g.render('decision_tree')
previsao = arvore.predict(x_tests)
previsao
confusao = confusion_matrix(y_tests, previsao)
confusao
acerto = accuracy_score(y_tests, previsao)
'acerto = {0:.2f}%'.format(acerto*100)<jupyter_output><empty_output><jupyter_text>Random Forest<jupyter_code>model = rfc(n_estimators=700, criterion='gini', max_depth=3, random_state=100)

model.fit(x_train, y_train)

probability = model.predict_proba(treinamento.drop('Survived', axis=1))[:, 1]

classification = model.predict(treinamento.drop('Survived', axis=1))

treinamento['probability'] = probability
treinamento['classification'] = classification

treinamento

result = treinamento[['Survived', 'probability', 'classification']]
result<jupyter_output><empty_output><jupyter_text>ACCURACY<jupyter_code>#model.fit(x_train, y_train)
x_test_pred = model.predict(x_test)

accuracy = accuracy_score(x_test_pred, y_test)

accuracy<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14766525166767738, 'fraction_numerical': 0.010612492419648272, 'mean_word_length': 9.150769230769232, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '629083', 'license': 'MIT', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1266, 'n_words': 163, 'path': 'titanic/ml_random_forest.ipynb', 'repo_name': 'Limarceu/kaggle', 'size': '3298'}