def plot_knn_var_threshold(self, drop: bool = True, norm: bool = False, thresholds: list = None, n_iter: int = 20, parity: bool = False, smote: bool = False): """ Plots the knn accuracy as function of n for given thresholds list. :return: --- <class 'NoneType'> """ if thresholds is None: thresholds = [ 0.81, 0.83, 0.85, 0.87, 0.89, 0.91, 0.93, 0.95, 0.97, 0.99 ] else: thresholds = sorted(thresholds) if parity: nvalues = [2 * i + 2 for i in range(round(n_iter / 2))] else: nvalues = [2 * i + 1 for i in range(round(n_iter / 2))] if drop: x = len(thresholds) fig, axs = plt.subplots(int(x / 5), int(x / (x / 5)), figsize=(15, 6), squeeze=False) fig.subplots_adjust(hspace=.5, wspace=.001) axs = axs.ravel() for j in range(int(len(thresholds))): axs[j].set_title('n') layout = pF.LayoutStyleObject( title='KNN variants - threshold ' + str(thresholds[j]), xlabel='n', ylabel='accuracy', grid=True) pF.multiple_line_chart(axs[j], nvalues, self.compute_knn(drop, norm, thresholds[j], n_iter, parity, smote=smote), layout=layout, percentage=True, legends=True) fig.tight_layout() plt.show() else: plt.figure() pF.multiple_line_chart(plt.gca(), nvalues, self.compute_knn(drop, norm, thresholds), title='KNN variants', xlabel='n', ylabel='accuracy', percentage=True) plt.show()
def plot_forest_features(self, drop: bool = True, norm: bool = False, thresholds: list = None, idx: int = -1): """ Plot the forest features obtained previously. :return: --- <class 'NoneType'> """ if thresholds is None: thresholds = [1] else: thresholds = sorted(thresholds) max_features = ['sqrt', 'log2'] n_estimators = [5, 10, 25, 50, 75, 100, 150, 200, 250, 300] thr_len = len(thresholds) fig, axs = plt.subplots(thr_len, 2, figsize=(10, 4), squeeze=False) for i in range(thr_len): aux = self.compute_forest_features(drop, norm, thresholds[i], idx) for k in range(len(max_features)): layout = pF.LayoutStyleObject( title='Random Forests with %s features' % max_features[k] + '[T=' + str(thresholds[i]) + ']', xlabel='Number of estimators', ylabel='Accuracy', grid=True) pF.multiple_line_chart(axs[i, k], n_estimators, aux[k], layout=layout, percentage=True) plt.show()
def plot_tree_criteria(self, drop: bool = True, norm: bool = False, thresholds: list = None, idx: int = -1): """ For the given thresholds, plots the decision trees criteria, according to 'entropy' and 'gini' criteria. :return: --- <class 'NoneType'> """ if thresholds is None: thresholds = [1] else: thresholds = sorted(thresholds) criteria = ['entropy', 'gini'] min_samples_leaf = [.10] thr_len = len(thresholds) fig, axs = plt.subplots(thr_len, 2, figsize=(10, 4), squeeze=False) for i in range(thr_len): for k in range(len(criteria)): layout = pF.LayoutStyleObject( title='Decision Trees with %s criteria' % criteria[k] + '[T=' + str(thresholds[i]) + ']', xlabel='Number of estimators', ylabel='Accuracy', grid=True) pF.multiple_line_chart(axs[i, k], min_samples_leaf, self.compute_tree_criteria( drop, norm, thresholds[i], idx)[k], layout=layout, percentage=True) plt.show()