<jupyter_start><jupyter_text>Modeling : Random Forest<jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Data load<jupyter_code>from scipy import sparse

X_train = sparse.load_npz("data/X_train.npz")
X_train
X_test = sparse.load_npz("data/X_test.npz")
X_test
y_train = pd.read_csv("data/X_train_TripType.csv")
y_train = y_train["TripType"]

print(y_train.shape)
y_train[:5]<jupyter_output>(95674,)<jupyter_text>Model<jupyter_code>from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=3000,
                               max_depth=15,
                               n_jobs=8)

model
%time model.fit(X_train, y_train)<jupyter_output>CPU times: user 8min 38s, sys: 6.31 s, total: 8min 45s
Wall time: 1min 17s<jupyter_text>Prediction<jupyter_code>prediction = model.predict(X_train)

print(prediction.shape)
prediction
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
confusion_matrix(y_train, prediction)
print(classification_report(y_train, prediction,
    target_names=['TripType_3', 'TripType_4', 'TripType_5', 'TripType_6',
       'TripType_7', 'TripType_8', 'TripType_9', 'TripType_12', 'TripType_14',
       'TripType_15', 'TripType_18', 'TripType_19', 'TripType_20',
       'TripType_21', 'TripType_22', 'TripType_23', 'TripType_24',
       'TripType_25', 'TripType_26', 'TripType_27', 'TripType_28',
       'TripType_29', 'TripType_30', 'TripType_31', 'TripType_32',
       'TripType_33', 'TripType_34', 'TripType_35', 'TripType_36',
       'TripType_37', 'TripType_38', 'TripType_39', 'TripType_40',
       'TripType_41', 'TripType_42', 'TripType_43', 'TripType_44',
       'TripType_999']))
prediction_prob = model.predict_proba(X_test)

print(prediction_prob.shape)
prediction_prob<jupyter_output>(95674, 38)<jupyter_text>Submission<jupyter_code>submission_columns = ['TripType_3', 'TripType_4', 'TripType_5', 'TripType_6',
       'TripType_7', 'TripType_8', 'TripType_9', 'TripType_12', 'TripType_14',
       'TripType_15', 'TripType_18', 'TripType_19', 'TripType_20',
       'TripType_21', 'TripType_22', 'TripType_23', 'TripType_24',
       'TripType_25', 'TripType_26', 'TripType_27', 'TripType_28',
       'TripType_29', 'TripType_30', 'TripType_31', 'TripType_32',
       'TripType_33', 'TripType_34', 'TripType_35', 'TripType_36',
       'TripType_37', 'TripType_38', 'TripType_39', 'TripType_40',
       'TripType_41', 'TripType_42', 'TripType_43', 'TripType_44',
       'TripType_999']

X_submission = pd.DataFrame(prediction_prob, columns=submission_columns)
test = pd.read_csv("data/test.csv")
X_submission["VisitNumber"] = test["VisitNumber"].unique()
submission_columns.insert(0, 'VisitNumber')
submission = X_submission[submission_columns]
submission.head()
#submission.to_csv("submission02.csv", index=False)<jupyter_output><empty_output>