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

Wrote my own color function not working..I dont know how much I am right #94

Closed
mlnjsh opened this issue May 28, 2018 · 2 comments
Closed

Comments

@mlnjsh
Copy link

mlnjsh commented May 28, 2018

Hi @ dev

I am sure you will solve this issue..
I am sendng you relevant part of code here

graph = mapper.map(projected_data,X,nr_cubes=14,overlap_perc=0.8,clusterer=sklearn.cluster.DBSCAN(eps=15, min_samples=4))


model = ensemble.IsolationForest(random_state=1729)
model.fit(X)
usecolor = model.decision_function(X).reshape((X.shape[0], 1))

node=graph['nodes'].values()
cluster= list(node)
# My own Function..I am trying to color each node by avg anomaly score of the data points in that node
z=[]
for i in range(0,len(cluster)):   
    z.append(np.round(np.mean(usecolor[cluster[i]])*10,decimals=4,out=None))  
print(z)
s=np.asarray(z)
s

I am getting following output

Mapping on data shaped (150, 4) using lens shaped (150, 2)

Creating 196 hypercubes.

Created 57 edges and 24 nodes in 0:00:00.054112.
[0.6021, 0.4893, 0.2385, -0.2715, 0.7183, 0.7395, 0.6809, 0.4972, 0.333, 0.6087, 0.6839, 0.5749, 0.3008, 0.4609, 0.3176, 0.2205, 0.1462, -0.05, 0.4609, 0.4583, 0.0631, 0.559, 0.5166, 0.1199]

array([ 0.6021,  0.4893,  0.2385, -0.2715,  0.7183,  0.7395,  0.6809,
        0.4972,  0.333 ,  0.6087,  0.6839,  0.5749,  0.3008,  0.4609,
        0.3176,  0.2205,  0.1462, -0.05  ,  0.4609,  0.4583,  0.0631,
        0.559 ,  0.5166,  0.1199])

Now I go to next part of code

# Visualize it

mapper.visualize(simplicial_complex, path_html="/home/dhananjay/kepler-mapper/keplermapper-iris.html", custom_meta={"Data:": "Me"}, custom_tooltips=Y,color_function=z)

But I am getting error

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-14-0692ad6431ec> in <module>()
      6         0.4972,  0.333 ,  0.6087,  0.6839,  0.5749,  0.3008,  0.4609,
      7         0.3176,  0.2205,  0.1462, -0.05  ,  0.4609,  0.4583,  0.0631,
----> 8         0.559 ,  0.5166,  0.1199]))

~/kepler-mapper/kmapper/kmapper.py in visualize(self, graph, color_function, custom_tooltips, custom_meta, path_html, title, save_file, X, X_names, lens, lens_names, show_tooltips)
    507         mapper_data = format_mapper_data(graph, color_function, X,
    508                                          X_names, lens,
--> 509                                          lens_names, custom_tooltips, env)
    510 
    511         histogram = graph_data_distribution(graph, color_function)

~/kepler-mapper/kmapper/visuals.py in format_mapper_data(graph, color_function, X, X_names, lens, lens_names, custom_tooltips, env)
     58     for i, (node_id, member_ids) in enumerate(graph["nodes"].items()):
     59         node_id_to_num[node_id] = i
---> 60         c = _color_function(member_ids, color_function)
     61         t = _type_node()
     62         s = _size_node(member_ids)

~/kepler-mapper/kmapper/visuals.py in _color_function(member_ids, color_function)
    219 
    220 def _color_function(member_ids, color_function):
--> 221     return _color_idx(np.mean(color_function[member_ids]))
    222     # return int(np.mean(color_function[member_ids]) * 30)
    223 

IndexError: index 50 is out of bounds for axis 1 with size 24

@mlnjsh mlnjsh changed the title Wrote my own color function not working Wrote my own color function not working..I dont know how much I am right May 28, 2018
@sauln
Copy link
Member

sauln commented May 29, 2018

The color_function is must have the same number of entries as data points. So for you dataset with 150 observations, you would need it length 150, with each entry associated to each observation. The visualize method will then take the average of these values for you.

Try passing the results of usecolor in:

mapper.visualize(simplicial_complex, path_html="...", 
                 custom_meta={"Data:": "Me"}, 
                 custom_tooltips=Y,
                 color_function=usecolor)

@mlnjsh
Copy link
Author

mlnjsh commented May 30, 2018

Thanku so much...I got it

@sauln sauln closed this as completed May 30, 2018
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

2 participants