Giter Club home page Giter Club logo

Comments (8)

parrt avatar parrt commented on May 14, 2024 1

hi. Seems like X_train, y_train are a bit out of sync sizewise based upon that error msg.

from dtreeviz.

georgesteve avatar georgesteve commented on May 14, 2024

Thank you for the answer!
You are right, I'm really sorry, I uploaded that error by mistake, I actually wanted to upload this one:

--------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-40-4568def0d1f4> in <module>
     76                       azim=35,
     77                       dist=12,
---> 78                       show={'splits','title'})
     79 
     80 

~/anaconda3/lib/python3.7/site-packages/dtreeviz/trees.py in rtreeviz_bivar_3D(ax, X_train, y_train, max_depth, feature_names, target_name, fontsize, ticks_fontsize, fontname, azim, elev, dist, show, colors, n_colors_in_map)
    246 
    247     for node, bbox in tesselation:
--> 248         plane(node, bbox)
    249 
    250     x, y, z = X_train[:, 0], X_train[:, 1], y_train

~/anaconda3/lib/python3.7/site-packages/dtreeviz/trees.py in plane(node, bbox)
    230         # print(f"{color_map[int(((node.prediction()-y_lim[0])/y_range)*(n_colors_in_map-1))]}")
    231         ax.plot_surface(xx, yy, z, alpha=.85, shade=False,
--> 232                         color=color_map[int(((node.prediction()-y_lim[0])/y_range)*(n_colors_in_map-1))],
    233                         edgecolor=colors['edge'], lw=.3)
    234 

IndexError: list index out of range

from dtreeviz.

parrt avatar parrt commented on May 14, 2024

ah. are there more than 10 classes? Can't do more than that.

from dtreeviz.

georgesteve avatar georgesteve commented on May 14, 2024

No, that's the fact, first I though the error was because I was using many classes, but actually in this case there are only two classes.

from dtreeviz.

parrt avatar parrt commented on May 14, 2024

Weird. Any chance you could send me a small data set that reproduces this?

from dtreeviz.

georgesteve avatar georgesteve commented on May 14, 2024

This is my code, I only was trainning:

from sklearn.datasets import *
from sklearn import tree
from dtreeviz.trees import *

from mpl_toolkits.mplot3d import Axes3D




data = pd.DataFrame({'Edad': [ 17, 64, 18, 20, 38, 49, 55, 25, 29,  31, 33, 52, 65, 27, 39,  54, 30, 28, 27, 18, 47],
                     'Sexo': ['H', 'M', 'M', 'M', 'M', 'H', 'H', 'M', 'H', 'H', 'H', 'M', 'M', 'M', 'M',  'H', 'H', 'H', 'M', 'H', 'M'],
                      'Salario': [25, 80, 22, 36, 37, 59, 74, 70, 33, 102, 88, 35, 70, 51, 38,  94, 50, 35, 74, 32, 45], 
                      'Pagador': [1,   0,  1,  0,  1,  0,  0,  1,  1,   0,  1,  0,  0,  1,  1,   0,  1,  0,  0,  1,  0]})


from sklearn import preprocessing
code = preprocessing.LabelEncoder()
code.fit(["H", "M"])
data['Sexo']= code.transform(data['Sexo'])
data = data.sort_values('Edad')


features = [2,0]
X = data.values[:,features]
print(X)


y = data['Pagador'].values
print(y)

figsize = (42,16)
fig = plt.figure(figsize=figsize)
ax = fig.add_subplot(111, projection='3d')
t = rtreeviz_bivar_3D(ax,
                      X,y,
                      max_depth=None,
                      feature_names=['Edad','Sexo'],
                      target_name='Pagador',
                      fontsize=11,
                      elev=30,
                      azim=35,
                      dist=12,
                      show={'splits','title'})



plt.show()

Actually I tried with other internet data sets and every work fine, for example in the image. I am a little confused.
image

Thank you for your support.

from dtreeviz.

parrt avatar parrt commented on May 14, 2024

Heh, don't you want a classifier here not a regressor? Pagador looks boolean

from dtreeviz.

parrt avatar parrt commented on May 14, 2024

I think you want:

ctreeviz_bivar(ax, X, y, max_depth=5,
               feature_names=['Edad', 'Sexo'],
               class_names=['yes', 'no'],
               target_name='Pagador',
               show={'splits', 'title'},
               colors={'scatter_edge': 'black'}
               )

Regardless, I fixed so {0,1} doesn't cause crash for regression partitioning :)

from dtreeviz.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.