MCPcopy
hub / github.com/AutoViML/AutoViz / draw_kdeplot_hv

Function draw_kdeplot_hv

autoviz/AutoViz_Holo.py:332–395  ·  view source on GitHub ↗
(dfin, cats, nums, chart_format, problem_type, dep, ls_objects, mk_dir, verbose=0)

Source from the content-addressed store, hash-verified

330
331#####################################################################################################
332def draw_kdeplot_hv(dfin, cats, nums, chart_format, problem_type, dep, ls_objects, mk_dir, verbose=0):
333 ensure_hvplot_imported()
334 dft = copy.deepcopy(dfin)
335 image_count = 0
336 imgdata_list = list()
337 N = len(nums)
338 cols = 2
339 plot_name = 'kde_plots'
340 width_size = 600
341 height_size = 400
342 hv_all = None
343 transparent = 0.5
344 color = 'lightblue'
345
346 ########################################################################################
347 def return_dynamic_objects(dfout, dep, title='Distribution of Target variable'):
348 width_size = 600
349 height_size = 400
350 pdf1 = pd.DataFrame(dfout[dep].value_counts().reset_index())
351 pdf2 = pd.DataFrame(dfout[dep].value_counts(1).reset_index())
352 drawobj41 = pdf1.hvplot(kind='bar', color='lightblue', title=title).opts(
353 height=height_size, width=width_size, xrotation=70)
354 drawobj42 = pdf2.hvplot(kind='bar', color='lightgreen', title=title)
355 return drawobj41 + drawobj42
356
357 if problem_type.endswith('Classification'):
358 colors = cycle('brycgkbyrcmgkbyrcmgkbyrcmgkbyr')
359 dmap = hv.DynamicMap(return_dynamic_objects(dfin, dep, title='Percent Distribution of Target variable'
360 ).opts(shared_axes=False).opts(
361 title='Histogram and KDE of Target = %s' % dep)).opts(
362 height=height_size, width=width_size)
363 dmap.opts(framewise=True, axiswise=True) ## both must be True for your charts to have dynamically varying axes!
364 hv_all = pn.pane.HoloViews(dmap) # , sizing_mode="stretch_both")
365 # ls_objects.append(drawobj41)
366 # ls_objects.append(drawobj42)
367 else:
368 if not isinstance(dep, list):
369 ### it means dep is a string ###
370 if dep == '':
371 ### there is no target variable to draw ######
372 return ls_objects
373 else:
374 dmap = hv.Distribution(dfin[dep]).opts(color=color,
375 height=height_size, width=width_size, alpha=transparent,
376 title='KDE (Distribution) Plot of Target Variable')
377 hv_all = pn.pane.HoloViews(dmap)
378 # ls_objects.append(drawobj41)
379 # ls_objects.append(drawobj42)
380 #### In this case we are using multiple objects in panel ###
381 ##### Save all the chart objects here ##############
382 if verbose == 2:
383 imgdata_list = append_panels(hv_all, imgdata_list, chart_format)
384 image_count += 1
385 if chart_format.lower() in ['server', 'bokeh_server', 'bokeh-server']:
386 ### If you want it on a server, you use drawobj.show()
387 # (drawobj41+drawobj42).show()
388 print('%s can be found in URL below:' % plot_name)
389 server = pn.serve(hv_all, start=True, show=True)

Callers 1

AutoViz_HoloFunction · 0.85

Calls 4

ensure_hvplot_importedFunction · 0.85
return_dynamic_objectsFunction · 0.85
append_panelsFunction · 0.85
save_html_dataFunction · 0.85

Tested by

no test coverage detected