hana_ml.visualizers package

The Visualizers Package consists of the following sections:

hana_ml.visualizers.eda

This module represents an eda plotter. Matplotlib is used for all visualizations.

class hana_ml.visualizers.eda.EDAVisualizer(ax=None, size=None, cmap=None, title=None)

Bases: hana_ml.visualizers.visualizer_base.Visualizer

Class for all EDA visualizations, including:
  • Distribution plot

  • Pie plot

  • Correlation plot

  • Scatter plot

  • Bar plot

  • Box plot

Parameters

ax : matplotlib.Axes, optional

The axes to use to plot the figure. Default value : Current axes

size : tuple of integers, optional

(width, height) of the plot in dpi Default value: Current size of the plot

title : str, optional

This plot’s title. Default value : Empty str

Attributes

ax

Returns the matplotlib Axes where the Visualizer will draw.

cmap

Returns the color map being used for the plot.

size

Returns the size of the plot in pixels.

title

Returns the title of the plot.

Methods

bar_plot(data, column, aggregation[, title])

Returns a bar plot for the HANA DataFrame column specified.

box_plot(data, column[, outliers, title, …])

Returns a box plot for the HANA DataFrame column specified.

correlation_plot(data[, corr_cols, label, cmap])

Returns a correlation plot for the HANA DataFrame columns specified.

distribution_plot(data, column, bins[, …])

Returns a distribution plot for the HANA DataFrame column specified.

pie_plot(data, column[, explode, title, legend])

Returns a pie plot for the HANA DataFrame column specified.

scatter_plot(data, x, y, x_bins, y_bins[, …])

Returns a scatter plot for the HANA DataFrame columns specified.

set_ax(ax)

Sets the Axes

set_cmap(cmap)

Sets the colormap

set_size(size)

Sets the size

set_title(title)

Sets the title of the plot

distribution_plot(data, column, bins, title=None, x_axis_fontsize=10, x_axis_rotation=90, debrief=True)

Returns a distribution plot for the HANA DataFrame column specified.

Parameters

data : DataFrame

DataFrame to use for the plot.

column : str

Column in the DataFrame being plotted.

bins : int

Number of bins to create based on the value of column.

title : str, optional

Title for the plot.

x_axis_fontsize : int, optional

Size of x axis labels

x_axis_rotation : int, optional

Rotation of x axis labels

debrief : bool, optional

Include skewness debrief

Returns

ax : Axes

The axes for the plot.

bin_data : pandas.DataFrame

The data used in the plot.

pie_plot(data, column, explode=0.03, title=None, legend=True)

Returns a pie plot for the HANA DataFrame column specified.

Parameters

data : DataFrame

DataFrame to use for the plot.

column : str

Column in the DataFrame being plotted.

explode : float, optional

Relative spacing between pie segments.

title : str, optional

Title for the plot.

legend : bool, optional

Legend for the plot.

Returns

ax : Axes

The axes for the plot. This can be used to set specific properties for the plot.

pie_data : pandas.DataFrame

The data used in the plot.

correlation_plot(data, corr_cols=None, label=True, cmap='RdYlBu')

Returns a correlation plot for the HANA DataFrame columns specified.

Parameters

data : DataFrame

DataFrame to use for the plot.

corr_cols : list of str, optional

Columns in the DataFrame being plotted. If None all numeric columns will be plotted.

label : bool, optional

Plot a colorbar.

cmap : matplotlib.pyplot.colormap, optional

Color map to use for the plot.

Returns

ax : Axes

The axes for the plot. This can be used to set specific properties for the plot.

corr : pandas.DataFrame

The data used in the plot.

scatter_plot(data, x, y, x_bins, y_bins, title=None, label=True, cmap='Blues', debrief=True)

Returns a scatter plot for the HANA DataFrame columns specified.

Parameters

data : DataFrame

DataFrame to use for the plot.

x : str

Column to be plotted on the x axis.

y : str

Column to be plotted on the y axis.

x_bins : int

Number of x axis bins to create based on the value of column.

y_bins : int

Number of y axis bins to create based on the value of column.

title : str, optional

Title for the plot.

label : str, optional

Label for the color bar.

cmap : matplotlib.pyplot.colormap, optional

Color map to use for the plot.

debrief : bool, optional

Include correlation debrief.

Returns

ax : Axes

The axes for the plot.

bin_matrix : pandas.DataFrame

The data used in the plot.

bar_plot(data, column, aggregation, title=None)

Returns a bar plot for the HANA DataFrame column specified.

Parameters

data : DataFrame

DataFrame to use for the plot.

column : str

Column to be aggregated.

aggregation : dict

Aggregation conditions (‘avg’, ‘count’, ‘max’, ‘min’).

title : str, optional

Title for the plot.

Returns

ax : Axes

The axes for the plot.

bar_data : pandas.DataFrame

The data used in the plot.

Examples

>>> ax1 = f.add_subplot(111)
>>> eda = EDAVisualizer(ax1)
>>> ax, bar_data = eda.bar_plot(data=data, column='COLUMN',
                                aggregation={'COLUMN':'count'})

Returns : bar plot (count) of ‘COLUMN’

>>> ax1 = f.add_subplot(111)
>>> eda = EDAVisualizer(ax1)
>>> ax, bar_data = eda.bar_plot(data=data, column='COLUMN',
                                aggregation={'OTHER_COLUMN':'avg'})

Returns : bar plot (avg) of ‘COLUMN’ against ‘OTHER_COLUMN’

box_plot(data, column, outliers=False, title=None, groupby=None)

Returns a box plot for the HANA DataFrame column specified.

Parameters

data : DataFrame

DataFrame to use for the plot.

column : str

Column in the DataFrame being plotted.

outliers : bool

Whether to plot suspected outliers and outliers.

title : str, optional

Title for the plot.

groupby : str, optional

Column to group by and compare.

Returns

ax : Axes

The axes for the plot.

cont : pandas.DataFrame

The data used in the plot.

ax

Returns the matplotlib Axes where the Visualizer will draw.

cmap

Returns the color map being used for the plot.

set_ax(ax)

Sets the Axes

set_cmap(cmap)

Sets the colormap

set_size(size)

Sets the size

set_title(title)

Sets the title of the plot

size

Returns the size of the plot in pixels.

title

Returns the title of the plot.

class hana_ml.visualizers.eda.Profiler

Bases: object

Class to build a HANA Profiler, including: - Variable descriptions - Missing values % - High cardinality % - Skewness - Numeric distributions - Categorical distributions - Correlations - High correlaton warnings

Methods

description(data, key[, bins, …])

Returns a HANA profiler, including: - Variable descriptions - Missing values % - High cardinality % - Skewness - Numeric distributions - Categorical distributions - Correlations - High correlaton warnings

set_size(fig, figsize)

Set the size of the data description plot, in inches.

description(data, key, bins=20, missing_threshold=10, card_threshold=100, skew_threshold=0.5, figsize=None)

Returns a HANA profiler, including: - Variable descriptions - Missing values % - High cardinality % - Skewness - Numeric distributions - Categorical distributions - Correlations - High correlaton warnings

Parameters

data : DataFrame

DataFrame to use for the plot.

key : str, optional

Key in the DataFrame.

bins : int, optional

Number of bins for numeric distributions. Default value = 20.

missing_threshold : float

Percentage threshold to display missing values.

card_threshold : int

Threshold for column to be considered with high cardinality.

skew_threshold : float

Absolute value threshold for column to be considered as highly skewed.

tight_layout : bool, optional

Use matplotlib tight layout or not.

figsize : tuple, optional

Size of figure to be plotted. First element is width, second is height.

Note: categorical columns with cardinality warnings are not plotted.

Returns

fig : Figure

matplotlib axis of the profiler

set_size(fig, figsize)

Set the size of the data description plot, in inches.

Parameters

fig : ax

The returned axes constructed by the description method.

figsize : tuple

Tuple of width and height for the plot.

hana_ml.visualizers.metrics

This module represents a visualizer for metrics.

class hana_ml.visualizers.metrics.MetricsVisualizer(ax=None, size=None, cmap=None, title=None)

Bases: hana_ml.visualizers.visualizer_base.Visualizer, object

The MetricVisualizer is used to visualize metrics.

Parameters

ax : matplotlib.Axes, optional

The axes to use to plot the figure. Default value : Current axes

size : tuple of integers, optional

(width, height) of the plot in dpi Default value: Current size of the plot

title : str, optional

This plot’s title. Default value : Empty str

Attributes

ax

Returns the matplotlib Axes where the Visualizer will draw.

cmap

Returns the color map being used for the plot.

size

Returns the size of the plot in pixels.

title

Returns the title of the plot.

Methods

plot_confusion_matrix(df[, normalize])

This function plots the confusion matrix and returns the Axes where this is drawn.

set_ax(ax)

Sets the Axes

set_cmap(cmap)

Sets the colormap

set_size(size)

Sets the size

set_title(title)

Sets the title of the plot

plot_confusion_matrix(df, normalize=False)

This function plots the confusion matrix and returns the Axes where this is drawn.

Parameters

df : DataFrame

Data points to the resulting confusion matrix. This dataframe’s columns should match columns (‘CLASS’, ‘’)

ax

Returns the matplotlib Axes where the Visualizer will draw.

cmap

Returns the color map being used for the plot.

set_ax(ax)

Sets the Axes

set_cmap(cmap)

Sets the colormap

set_size(size)

Sets the size

set_title(title)

Sets the title of the plot

size

Returns the size of the plot in pixels.

title

Returns the title of the plot.

hana_ml.visualizers.m4_sampling

M4 algorithm for sampling query

hana_ml.visualizers.m4_sampling.get_min_index(hana_df)

Get Minimum Timestamp of Time Series Data

Parameters

hana_df : DataFrame

Time series data whose 1st column is index and 2nd one is value.

Returns

datetime

Return the minimum timestamp.

hana_ml.visualizers.m4_sampling.get_max_index(hana_df)

Get Maximum Timestamp of Time Series Data

Parameters

hana_df : DataFrame

Time series data whose 1st column is index and 2nd one is value.

Returns

datetime

Return the maximum timestamp.

hana_ml.visualizers.m4_sampling.m4_sampling(hana_df, width)

M4 algorithm for big data visualization

Parameters

hana_df : DataFrame

Data to be sampled. Time seires data whose 1st column is index and 2nd one is value.

width : int

Sampling Rate. It is an indicator of how many pixels being in the picture.

Returns

DataFrame

Return the sampled dataframe.