def plot_global_decisions(self, colors=None, enable_node_id=True, random_state=0, file_name="interpretable_tree.png", show_img=False, fig_size=(20, 8)): """ Visualizes the decision policies of the surrogate tree. """ graph_inst = plot_tree(self.__model, self.__model_type, feature_names=self.feature_names, color_list=colors, class_names=self.class_names, enable_node_id=enable_node_id, seed=random_state) f_name = "interpretable_tree.png" if file_name is None else file_name graph_inst.write_png(f_name) try: import matplotlib matplotlib.use('agg') import matplotlib.pyplot as plt except ImportError: raise exceptions.MatplotlibUnavailableError( "Matplotlib is required but unavailable on the system.") except RuntimeError: raise exceptions.MatplotlibDisplayError( "Matplotlib unable to open display") if show_img: plt.rcParams["figure.figsize"] = fig_size img = plt.imread(f_name) if self.__model_type == 'regressor': cax = plt.imshow(img, cmap=plt.cm.get_cmap( graph_inst.get_colorscheme())) plt.colorbar(cax) else: plt.imshow(img) return graph_inst
from sklearn.externals.six import StringIO from sklearn.tree import export_graphviz import pydotplus import numpy as np from skater.util import exceptions try: from matplotlib.colors import rgb2hex import matplotlib.pyplot as plt except ImportError: raise (exceptions.MatplotlibUnavailableError( "matplotlib is required but unavailable on the system.")) # reference: http://wingraphviz.sourceforge.net/wingraphviz/language/colorname.htm # TODO: Make the color scheme for regression and classification homogeneous color_schemes = [ 'aliceblue', 'antiquewhite', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkgoldenrod', 'darkgreen', 'darkkhaki', 'darkolivegreen', 'darkorange', 'darkorchid', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrod', 'lightgoldenrodyellow', 'lightgray', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslateblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'limegreen', 'linen', 'magenta', 'maroon',
from skater.util import exceptions try: import plotly.offline as py py.init_notebook_mode(connected=True) import plotly.graph_objs as go from plotly import tools except ImportError: raise exceptions.PlotlyUnavailableError("plotly is required but unavailable on your system.") try: import matplotlib.pyplot as plt from matplotlib.colors import ListedColormap from matplotlib import colors as mcolors except ImportError: raise exceptions.MatplotlibUnavailableError("Matplotlib is required but unavailable on your system.") _enable_axis = lambda ax, flag: ax.axis("on") if flag is True else ax.axis("off") def _create_meshgrid(xx, yy, plot_step=0.02): xmin, xmax = xx.min() - 0.5, xx.max() + 0.5 ymin, ymax = yy.min() - 0.5, yy.max() + 0.5 xx, yy = np.meshgrid(np.arange(xmin, xmax, plot_step), np.arange(ymin, ymax, plot_step)) x_ = pd.DataFrame({'F1': xx.ravel(), 'F2': yy.ravel()}) return x_, xx, yy def _generate_contours(est, X_, xx, yy, color_map, ax, **params): Z = est.predict(X_).reshape(xx.shape)