def plot(self, objects=None, title="Reverse cumulative distribution of |residual|", show=False): """ Plot function for ModelPerformance class. :param objects: object of ModelPerformance class or list or tuple containing such objects :param title: str, the plot's title :param show: True shows the plot, False returns the plotly Figure object that can be edited or saved using `write_image()` method :return None or plotly Figure (see :param show) """ # are there any other objects to plot? if objects is None: n = 1 _residuals_df_list = [self.residuals.copy()] elif isinstance(objects, self.__class__): # allow for objects to be a single element n = 2 _residuals_df_list = [self.residuals.copy(), objects.residuals.copy()] else: # objects as tuple or array n = len(objects) + 1 _residuals_df_list = [self.residuals.copy()] for ob in objects: if not isinstance(ob, self.__class__): raise TypeError("Some explanations aren't of ModelPerformance class") _residuals_df_list += [ob.residuals.copy()] fig = go.Figure() for i in range(n): _residuals_df = _residuals_df_list[i] _abs_residuals = np.abs(_residuals_df['residuals']) _unique_abs_residuals = np.unique(_abs_residuals) fig.add_scatter( x=_unique_abs_residuals, y=1 - ecdf(_abs_residuals)(_unique_abs_residuals), line_shape='hv', name=_residuals_df.iloc[0, _residuals_df.columns.get_loc('label')] ) fig.update_yaxes({'type': 'linear', 'gridwidth': 2, 'zeroline': False, 'automargin': True, 'ticks': 'outside', 'tickcolor': 'white', 'ticklen': 10, 'fixedrange': True, 'tickformat': ',.0%'}) fig.update_xaxes({'type': 'linear', 'gridwidth': 2, 'zeroline': False, 'automargin': True, 'ticks': "outside", 'tickcolor': 'white', 'ticklen': 10, 'fixedrange': True, 'title_text': '|residual|'}) fig.update_layout(title_text=title, title_x=0.15, font={'color': "#371ea3"}, template="none", margin={'t': 78, 'b': 71, 'r': 30}) if show: fig.show(config={'displaylogo': False, 'staticPlot': False, 'modeBarButtonsToRemove': ['sendDataToCloud', 'lasso2d', 'autoScale2d', 'select2d', 'zoom2d', 'pan2d', 'zoomIn2d', 'zoomOut2d', 'resetScale2d', 'toggleSpikelines', 'hoverCompareCartesian', 'hoverClosestCartesian']}) else: return fig
def plot(self, objects=None, title="Reverse cumulative distribution of |residual|", show=False): """Plot the Model Performance explanation Parameters ----------- objects : ModelPerformance object or array_like of ModelPerformance objects Additional objects to plot (default is None). title : str, optional Title of the plot (default depends on the `type` attribute). show : bool, optional True shows the plot; False returns the plotly Figure object that can be edited or saved using the `write_image()` method (default is True). Returns ----------- None or plotly.graph_objects.Figure Return figure that can be edited or saved. See `show` parameter. """ # are there any other objects to plot? if objects is None: _df_list = [self.residuals.copy()] elif isinstance( objects, self.__class__): # allow for objects to be a single element _df_list = [self.residuals.copy(), objects.residuals.copy()] else: # objects as tuple or array _df_list = [self.residuals.copy()] for ob in objects: if not isinstance(ob, self.__class__): raise TypeError( "Some explanations aren't of ModelPerformance class") _df_list += [ob.residuals.copy()] colors = get_default_colors(len(_df_list), 'line') fig = go.Figure() for i, _df in enumerate(_df_list): _abs_residuals = np.abs(_df['residuals']) _unique_abs_residuals = np.unique(_abs_residuals) fig.add_scatter(x=_unique_abs_residuals, y=1 - ecdf(_abs_residuals)(_unique_abs_residuals), line_shape='hv', name=_df.iloc[0, _df.columns.get_loc('label')], marker=dict(color=colors[i])) fig.update_yaxes({ 'type': 'linear', 'gridwidth': 2, 'zeroline': False, 'automargin': True, 'ticks': 'outside', 'tickcolor': 'white', 'ticklen': 10, 'fixedrange': True, 'tickformat': ',.0%' }) fig.update_xaxes({ 'type': 'linear', 'gridwidth': 2, 'zeroline': False, 'automargin': True, 'ticks': "outside", 'tickcolor': 'white', 'ticklen': 10, 'fixedrange': True, 'title_text': '|residual|' }) fig.update_layout(title_text=title, title_x=0.15, font={'color': "#371ea3"}, template="none", margin={ 't': 78, 'b': 71, 'r': 30 }) if show: fig.show( config={ 'displaylogo': False, 'staticPlot': False, 'toImageButtonOptions': { 'height': None, 'width': None, }, 'modeBarButtonsToRemove': [ 'sendDataToCloud', 'lasso2d', 'autoScale2d', 'select2d', 'zoom2d', 'pan2d', 'zoomIn2d', 'zoomOut2d', 'resetScale2d', 'toggleSpikelines', 'hoverCompareCartesian', 'hoverClosestCartesian' ] }) else: return fig
def plot(self, objects=None, title="Reverse cumulative distribution of |residual|", show=False): """Plot the Model Performance explanation Parameters ----------- objects : ModelPerformance object or array_like of ModelPerformance objects Additional objects to plot (default is None). title : str, optional Title of the plot (default depends on the `type` attribute). show : bool, optional True shows the plot; False returns the plotly Figure object that can be edited or saved using the `write_image()` method (default is True). Returns ----------- None or plotly.graph_objects.Figure Return figure that can be edited or saved. See `show` parameter. """ # are there any other objects to plot? if objects is None: _df_list = [self.residuals.copy()] elif isinstance( objects, self.__class__): # allow for objects to be a single element _df_list = [self.residuals.copy(), objects.residuals.copy()] elif isinstance(objects, (list, tuple)): # objects as tuple or array _df_list = [self.residuals.copy()] for ob in objects: _global_checks.global_check_object_class(ob, self.__class__) _df_list += [ob.residuals.copy()] else: _global_checks.global_raise_objects_class(objects, self.__class__) colors = _theme.get_default_colors(len(_df_list), 'line') fig = go.Figure() for i, _df in enumerate(_df_list): _abs_residuals = np.abs(_df['residuals']) _unique_abs_residuals = np.unique(_abs_residuals) fig.add_scatter(x=_unique_abs_residuals, y=1 - ecdf(_abs_residuals)(_unique_abs_residuals), line_shape='hv', name=_df.iloc[0, _df.columns.get_loc('label')], marker=dict(color=colors[i])) fig.update_yaxes({ 'type': 'linear', 'gridwidth': 2, 'zeroline': False, 'automargin': True, 'ticks': 'outside', 'tickcolor': 'white', 'ticklen': 10, 'fixedrange': True, 'tickformat': ',.0%' }) fig.update_xaxes({ 'type': 'linear', 'gridwidth': 2, 'zeroline': False, 'automargin': True, 'ticks': "outside", 'tickcolor': 'white', 'ticklen': 10, 'fixedrange': True, 'title_text': '|residual|' }) fig.update_layout(title_text=title, title_x=0.15, font={'color': "#371ea3"}, template="none", margin={ 't': 78, 'b': 71, 'r': 30 }) if show: fig.show(config=_theme.get_default_config()) else: return fig