<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Importing data
Getting data from kaggle first 
Step1:  Baseline model
Step2:  Deep Forest
By Hand
Step3:  This is not very handy, not at all. We already see a lot of code duplication, and one may feel there may be a way to abstract a lot of the logic that is happening here, in a way that is more flexible and powerful that all this boilerplate code.
With API
Step4:  Going Further
<ASSISTANT_TASK:>
Python Code:
import pkg_resources
raw_data = pd.read_csv(pkg_resources.resource_stream('deepforest', 'data/train.csv'))
clean_data = raw_data.drop(["Cabin", "Name", "PassengerId", "Ticket"], axis=1)
clean_data = pd.get_dummies(clean_data).fillna(-1)
train, test = train_test_split(clean_data)
def split_x_y(dataframe, target):
    return dataframe.drop(target, axis=1), dataframe[target]
X_train, y_train = split_x_y(train, "Survived")
X_test, y_test = split_x_y(test, "Survived")
Explanation: Importing data
Getting data from kaggle first :
End of explanation
rf = RandomForestClassifier(n_estimators=100, n_jobs=-1)
rf.fit(X_train, y_train)
y_pred = rf.predict_proba(X_test)
auc = roc_auc_score(y_true=y_test, y_score=y_pred[:, 1])
auc
Explanation: Baseline model
End of explanation
from sklearn.model_selection import StratifiedKFold
rf1 = RandomForestClassifier(n_estimators=100, n_jobs=-1, max_depth=4)
rf2 = RandomForestClassifier(n_estimators=100, n_jobs=-1, max_depth=10)
rf1.fit(X_train, y_train)
y_pred_train_1 = rf1.predict_proba(X_train)
y_pred_test_1 = rf1.predict_proba(X_test)
y_pred_train_1 = pd.DataFrame(y_pred_train_1, columns=["rf1_0", "rf1_1"], index=X_train.index)
y_pred_test_1 = pd.DataFrame(y_pred_test_1, columns=["rf1_0", "rf1_1"], index=X_test.index)
rf2.fit(X_train, y_train)
y_pred_train_2 = rf2.predict_proba(X_train)
y_pred_test_2 = rf2.predict_proba(X_test)
y_pred_train_2 = pd.DataFrame(y_pred_train_2, columns=["rf2_0", "rf2_1"], index=X_train.index)
y_pred_test_2 = pd.DataFrame(y_pred_test_2, columns=["rf2_0", "rf2_1"], index=X_test.index)
hidden_train_1 = pd.concat([X_train, y_pred_train_1, y_pred_train_2], axis=1)
hidden_test_1 = pd.concat([X_test, y_pred_test_1, y_pred_test_2], axis=1)
hidden_train_1.head()
rf3 = RandomForestClassifier(n_estimators=300, n_jobs=-1)
rf3.fit(hidden_train_1, y_train)
y_pred3 = rf3.predict_proba(hidden_test_1)
roc_auc_score(y_test, y_pred3[:, 1])
Explanation: Deep Forest
By Hand
End of explanation
from deepforest.layer import Layer, InputLayer
input_layer = InputLayer(RandomForestClassifier(n_estimators=100, n_jobs=-1, max_depth=4),
                         RandomForestClassifier(n_estimators=100, n_jobs=-1, max_depth=10))
hidden_layer = Layer(input_layer,
                     RandomForestClassifier(n_estimators=50, n_jobs=-1, max_depth=4),
                     RandomForestClassifier(n_estimators=50, n_jobs=-1, max_depth=10))
hidden_layer.fit(X_train, y_train)
pd.DataFrame(hidden_layer.predict(X_test), index=X_test.index)
Explanation: This is not very handy, not at all. We already see a lot of code duplication, and one may feel there may be a way to abstract a lot of the logic that is happening here, in a way that is more flexible and powerful that all this boilerplate code.
With API
End of explanation
def random_forest_generator():
    for i in range(2, 15, 2):
        yield RandomForestClassifier(n_estimators=100,
                                     n_jobs=-1,
                                     min_samples_leaf=5,
                                     max_depth=i)
    for i in range(2, 15, 2):
        yield RandomForestClassifier(n_estimators=100,
                                     n_jobs=-1,
                                     max_features=1,
                                     min_samples_leaf=5,
                                     max_depth=i)
def paper_like_generator():
    for i in range(2):
        yield RandomForestClassifier(n_estimators=1000,
                                     n_jobs=-1,
                                     min_samples_leaf=10)
    for i in range(2):
        yield RandomForestClassifier(n_estimators=1000,
                                     n_jobs=-1,
                                     max_features=1,
                                     min_samples_leaf=10)
def build_input_layer():
    return InputLayer(*paper_like_generator())
def build_hidden_layer(layer):
    return Layer(layer, *paper_like_generator())
def build_output_layer(layer):
    return Layer(layer,
                 RandomForestClassifier(n_estimators=500,
                                        n_jobs=-1,
                                        min_samples_leaf=5,
                                        max_depth=10))
input_l = build_input_layer()
hidden_1 = build_hidden_layer(input_l)
hidden_2 = build_hidden_layer(hidden_1)
hidden_3 = build_hidden_layer(hidden_2)
hidden_4 = build_hidden_layer(hidden_3)
output_l = build_output_layer(hidden_4)
output_l.fit(X_train, y_train)
y_pred = output_l.predict(X_test)
y_pred
roc_auc_score(y_test, y_pred[:, 1])
Explanation: Going Further
End of explanation
<END_TASK>