Skip to content

The path of dtreeviz to show the sample prediction results is wrong when using iloc directly to select data from the dataframe #329

@flystar233

Description

@flystar233

dtreeviz version: 2.2.2

from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestRegressor
import matplotlib.pyplot as plt
from sklearn import tree
import dtreeviz
import pandas as pd

iris = load_iris()
data = pd.DataFrame(iris.data)
X = data.iloc[:,1:4]
y = data.iloc[:,0]
fn=["sepal width","petal length","petal width"]
cn ="sepal length"
clf = RandomForestRegressor(max_depth=4,random_state=2024,min_samples_leaf=10,n_estimators=10,oob_score=True )
clf.fit(X, y)
model = clf.estimators_[0]
no_dup = list(set(clf.estimators_samples_[0]))
X_in = X.loc[no_dup]
y_in = y.loc[no_dup]
viz_model = dtreeviz.model(model,
                           X_train = X_in,
                           y_train  = y_in,
                           feature_names=fn,
                           target_name=cn)
v = viz_model.view(x=X.iloc[0,:])     # render as SVG into internal object 
v.show()   

image

v = viz_model.view(x=[3.5,1.4,0.2])

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions