text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.model_selection import train_test_split

from sklearn.preprocessing import LabelEncoder

import pandas as pd

import pandas as pd
dfTrain = pd.read_csv('../input/train.csv')
dfTest = pd.read_csv('../input/test.csv')

from sklearn.preprocessing import LabelEncoder
dfCombined = pd.concat([dfTrain, dfTest])
for feature in list(dfCombined):
    le = LabelEncoder()
    le.fit(dfCombined[feature])
    if feature in dfTrain:
        dfTrain[feature] = le.transform(dfTrain[feature])
    if feature in dfTest:
        dfTest[feature] = le.transform(dfTest[feature])

from sklearn.model_selection import train_test_split
X = dfTrain.drop(['Survived'], axis=1)
y = dfTrain['Survived']
num_test = 0.2
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=num_test, random_state=23)

from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier()
clf.fit(X_train, y_train)
predictions = clf.predict(X_test)

clf = RandomForestClassifier()
clf.fit(X, y)
dfTestPredictions = clf.predict(dfTest)
results = pd.DataFrame({'PassengerId': dfTest['PassengerId'], 'Survived': dfTestPredictions})
results.to_csv('results.csv', index=False)
results.head()