def ssr_curve(self, x, y, slopes=[ 0.1, 0.2, 0.3, 0.4, 0.5, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 7.5, 10.0 ]): ssrs = [] for slope in slopes: yint = (np.mean(y) - slope * np.mean(x)) ssrs.append( self.get_ss_res(zip(x, y), lambda val: slope * val + yint)) image_manager = ImageManager() plotter = Plotter() plotter.set_title('Sum of Squared Residuals') plotter.set_axis_labels('Slope Selected', 'Sum of Squared Residual') plotter.set_output_filename(g.files['ls-ssr']) ssr_plot = ScatterSketch() ssr_plot.add_x(slopes) ssr_plot.add_y(ssrs) plotter.load(ssr_plot) plotter.save() plotter.close() g.debug.prn(self, 'Drawn Sum of Squared Residuals Plot') image_manager.scale(g.files['ls-ssr'], g.files['ls-ssr'], 250)
def plot_roc(self): plotter = Plotter() plotter.set_title('Receiver Operating Characteristic') plotter.set_axis_labels('') plotter.set_output_filename() #TODO: Fill filename plotter.close() pass # Save the image as "roc.png"
def f_dist(self, model_type, trials): plotter = Plotter() image_manager = ImageManager() plotter.set_title('F Distribution') plotter.set_axis_labels('Frequency', 'F Score') plotter.set_output_filename(g.files['least-squares-f']) histogram = HistogramSketch() for i in range(trials): x_vals = g.randomizer.random_list(g.points_to_gen, g.lower_x_bound, g.upper_x_bound) y_vals = g.randomizer.random_list(g.points_to_gen, g.lower_y_bound, g.upper_y_bound) if model_type == LinearModel: slope, yint = self.least_squares_slope_yint_eqn(x_vals, y_vals) func = lambda x: slope * x + yint else: g.debug.prn(self, 'Incompatible model type.', 1) break ss_fit = self.get_ss_res(zip(x_vals, y_vals), func) ss_mean = self.get_ss_res(zip(x_vals, y_vals), lambda x: np.mean(x_vals)) p_fit = 2 # TODO: Update for Dataframe p_mean = 1 # "" n = len(x_vals) if ss_fit == 0 or (n - p_fit) == 0 or (p_fit - p_mean) == 0: self.debug.prn(self, 'F distribution cannot divide by zero.', 1) continue numerator = (ss_mean - ss_fit) / (p_fit - p_mean) denominator = ss_fit / (n - p_fit) histogram.add_x(numerator / denominator) histogram.set_bins() plotter.load(histogram) plotter.save() plotter.close() image_manager.scale(g.files['least-squares-f'], g.files['least-squares-f'], 250) self.debug.prn(self, 'F distribution created.')