text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import accuracy_score

from sklearn.model_selection import train_test_split

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

data = pd.read_csv('../input/loan.csv', low_memory=False)

data = data[(data.loan_status == 'Fully Paid') | (data.loan_status == 'Default')]

data['target'] = data.loan_status == 'Fully Paid'

data.shape

x = data.loan_amnt

term_groups = data.groupby('term')
term_groups['int_rate'].mean()

grade_groups = data.groupby('grade')
grade_groups['int_rate'].mean()

X = pd.get_dummies(data[['term', 'verification_status', 'purpose', 'policy_code', 'loan_amnt', 'funded_amnt', 'funded_amnt_inv', 'int_rate', 'emp_length', 'addr_state']])

X.shape

y = data['target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
X_train.shape

clf = RandomForestClassifier(n_estimators=100, max_depth=4, random_state=42)

clf.fit(X_train, y_train)

y_pred = clf.predict(X_test)

accuracy_score(y_test, y_pred)