Git Product home page Git Product logo

Comments (12)

Ashafix avatar Ashafix commented on September 13, 2024 1

Please have a look at Ashafix@ee02d0f
and let me know if it's the right direction.

  • Each function has an optional parameter colors which is a dictionary, each dictionary key can overwrite a default value.
  • The colors are stored in colors.py allowing easy global modification
  • Having a new optional parameter should allow re-use of all previous scripts which use dtreeviz
  • change_colors.py demonstrates the effects with a few examples
  • "tested" on Windows 10 and Ubuntu 16.04

from dtreeviz.

parrt avatar parrt commented on September 13, 2024

good idea!

from dtreeviz.

Ashafix avatar Ashafix commented on September 13, 2024

@dhaitz : How should the configuration look like in your opinion? Global or per function call?

As far as I could see from the code, the colors are currently just global constants which can be overwritten, e.g. dtreeviz.trees.GREY = "#ff0000" and you get red labels.

Probably the easiests way would be to have a global dictionary which stores the colors and can be overwritten for customization, e.g. COLORS = {'label': GREY, ', 'title': BLACK}

@parrt : Any preferences?

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

dtreeviz.trees.GREY = "#ff0000"

regr = tree.DecisionTreeRegressor(max_depth=2)
boston = load_boston()
regr.fit(boston.data, boston.target)

viz = dtreeviz.trees.dtreeviz(regr, boston.data, boston.target, target_name='price', feature_names=boston.feature_names)
              
viz.view()

image

from dtreeviz.

parrt avatar parrt commented on September 13, 2024

I think some kind of argument would be better than tweaking the globals.

from dtreeviz.

dhaitz avatar dhaitz commented on September 13, 2024

@Ashafix , @parrt : Maybe something like this in dtreeviz/trees.py?

GREY = "#ff0000"
...
COLORS = {'label': GREY, ', 'title': BLACK}

def dtreeviz(..., 
             colors: dict = None
             ):

    if colors is None:  # fall back to module-level default colors
        colors = COLORS

from dtreeviz.

parrt avatar parrt commented on September 13, 2024

or just colors:dict=COLORS?

from dtreeviz.

dhaitz avatar dhaitz commented on September 13, 2024

@parrt ah yes, of course this is the simple and straightforward solution.

Another approach would be:

if colors is None:
    colors = dict(COLORS, **colors)

which would allow you to overwrite only certain keys in the colors argument and use the defaults from COLORS for all others.

from dtreeviz.

parrt avatar parrt commented on September 13, 2024

@Ashafix Looks pretty good! widespread changes but it's adding a lot of control to the look of the plots. could you make a PR? I'm wondering if colors.py should be a separate file or included... thoughts?

from dtreeviz.

Ashafix avatar Ashafix commented on September 13, 2024

@parrt : Thanks for the quick feedback! Personal opinion, I'd prefer a separate file for the colors/configuration, but not my library.

I will test and document all parameters and then create a PR.

from dtreeviz.

parrt avatar parrt commented on September 13, 2024

sounds great. does extra file cause any package weirdness for users? if invisible, let's factor out into colors.py :)

from dtreeviz.

mattharrison avatar mattharrison commented on September 13, 2024

While you are on colors, could you do font's as well :) (Ie make them configurable)

from dtreeviz.

Ashafix avatar Ashafix commented on September 13, 2024

@mattharrison : one PR at a time...

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.