# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + id="8ZtuUVpcCEno" colab_type="code" colab={}
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# %matplotlib inline

# + id="l0gBTuTZCPp_" colab_type="code" colab={}
train = pd.read_csv("/content/train_mod.csv")

# + id="gJMuBPLsIBdW" colab_type="code" colab={}
tr = pd.read_csv("/content/train.csv")
y=tr["Survived"]

# + id="XI4MvhrtIBhQ" colab_type="code" colab={}


# + id="kSigtyYyChRw" colab_type="code" colab={}
test = pd.read_csv("/content/test_mod.csv")

# + id="wURpx3hFDF5A" colab_type="code" colab={}
X_test = test
X_test = X_test.drop(columns=["PassengerId"])

# + id="xNilALBuHlVS" colab_type="code" outputId="fd459bb1-f76d-4d8d-d82e-dccc7c9de63c" colab={"base_uri": "https://localhost:8080/", "height": 195}
train.head()

# + id="hcMtnZeXDNNy" colab_type="code" outputId="e61b5d03-b10a-44bd-efe2-5bf8512862fd" colab={"base_uri": "https://localhost:8080/", "height": 403}
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import GridSearchCV,StratifiedKFold,cross_val_score,train_test_split
from sklearn.metrics import accuracy_score
rfc = RandomForestClassifier(random_state=100)
param_grid = { 
    'n_estimators': [200, 500],
    'max_features': ['auto', 'sqrt', 'log2'],
    'max_depth' : [4,5,6,7,8],
    'criterion' :['gini', 'entropy']
}
kf = StratifiedKFold(n_splits=5)
grfc = GridSearchCV(estimator = rfc,param_grid=param_grid,cv=kf)
X_train,X_tes,y_train,y_test = train_test_split(train,y,random_state=69)
grfc.fit(X_train,y_train)

# + id="k2ZbRFVyKsr0" colab_type="code" outputId="3b561e5a-6e16-4ace-acb5-27c8c9f85416" colab={"base_uri": "https://localhost:8080/", "height": 34}
grfc.best_score_

# + id="d6YBB3hiLbns" colab_type="code" outputId="f7774311-0d5e-4664-e926-070c7c5c56c4" colab={"base_uri": "https://localhost:8080/", "height": 84}
grfc.best_params_

# + id="y8155B9zLfBe" colab_type="code" colab={}
y_pred1 = grfc.predict(X_tes)

# + id="hU4F_HEuLkAA" colab_type="code" outputId="a854c134-9e03-4451-9517-b545d524ee45" colab={"base_uri": "https://localhost:8080/", "height": 34}
accuracy_score(y_test,y_pred1)

# + id="691ZsEhwLpQM" colab_type="code" colab={}
y_pred1 = grfc.predict(X_test)

# + id="IF1rxJMtLwfu" colab_type="code" colab={}
rfc_grid= pd.DataFrame({
        "PassengerId": test["PassengerId"],
        "Survived": y_pred1
    })

# + id="l9SAdpu7MBQl" colab_type="code" colab={}
rfc_grid.to_csv("/content/rfc_grid_data12.csv", index=False)

# + id="SHnKXzsiMI6M" colab_type="code" colab={}


StarcoderdataJupyterScriptsDedupFiltered