Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flystar233 opened this issue Aug 31, 2024 · 0 comments

Comments

@flystar233
Copy link

flystar233 commented Aug 31, 2024

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

@flystar233 flystar233 changed the title The path that dtreeviz takes to show the results of the sample predictions is wrong The path of dtreeviz to show the sample prediction results is wrong when using iloc directly to select data from the dataframe Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant