Skip to content

Instantly share code, notes, and snippets.

@FelixChop
Last active August 6, 2018 05:46
Show Gist options
  • Select an option

  • Save FelixChop/eae55ee2636b17dd780cfc5484f3b8ed to your computer and use it in GitHub Desktop.

Select an option

Save FelixChop/eae55ee2636b17dd780cfc5484f3b8ed to your computer and use it in GitHub Desktop.
from treeinterpreter import treeinterpreter as ti
for i,row in X.iterrows():
data_point = pd.DataFrame([row])
data_point.set_axis(['value_variable']) # Once transposed, it will be the column name
prediction, bias, contributions = ti.predict(rf_model, data_point)
local_interpretation = data_point.append(
pd.DataFrame([[round(c[1],3) for c in contributions[0]]], columns=data_point.columns.tolist(), index=['contribution_variable'])
).T.sort_values('contribution_variable', ascending=False)
# print(local_interpretation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment