Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
    def plot(self):
        plotter = Plotter()
        image_manager = ImageManager()
        sketches = []
        plotter.set_output_filename(g.files['ridge-regression'])
        plotter.set_title('Ridge Regression')
        g.debug.prn(self, 'Plot basics set.')

        min_x = min(self.training_x)
        max_x = max(self.training_x)
        x_vals = []
        y_vals = []
        for x in range(min_x * 100, max_x * 100):
            x_vals.append([x / 100])
            y_vals.append([self.f(x / 100)])
        sketches.append(SmoothSketch())
        sketches[-1].add_x(x_vals)
        sketches[-1].add_y(y_vals)
        g.debug.prn(self, 'Linear curve saved as SmoothSketch.')

        sketches.append(ScatterSketch())
        sketches[-1].add_x(list(self.training_x))
        sketches[-1].add_y(list(self.training_y))
        g.debug.prn(self, 'Points saved as ScatterSketch.')

        for i in range(len(self.training_x)):
            if self.f(self.training_x[i]) > self.training_y[i]:
                y_max = self.f(self.training_x[i])
                y_min = self.training_y[i]
            else:
                y_min = self.f(self.training_x[i])
                y_max = self.training_y[i]
            sketches.append(VerticalLineSketch())
            sketches[-1].set_y_max(y_max)
            sketches[-1].set_y_min(y_min)
            sketches[-1].set_x(self.training_x[i])
            g.debug.prn(self, 'Vertical line appended.', 3)
        g.debug.prn(self, 'SSR lines drawn as VerticalLineSketch(s).')

        plotter.load(sketches)
        plotter.save()
        plotter.close()
        g.debug.prn(self, 'All sketches loaded and saved.')

        image_manager.scale(g.files['ridge-regression'],
                            g.files['ridge-regression'], 250)

        del plotter
        del image_manager
        g.debug.prn(self, 'Plotter and ImageManager objects deleted', 3)
Ejemplo n.º 3
0
    def plot(self):
        plotter = Plotter()
        image_manager = ImageManager()
        sketches = []
        plotter.set_output_filename(g.files['least-squares'])
        plotter.set_title('Least Squares')

        # min_x = min(self.training.get_output()[x_index])
        # max_x = max(self.training.get_output()[x_index])
        min_x = min(self.training_x)
        max_x = max(self.training_x)
        x_vals = []
        y_vals = []
        for x in range(min_x * 100, max_x * 100):
            x_vals.append([x / 100])
            y_vals.append([self.f(x / 100)])
        sketches.append(SmoothSketch())
        sketches[-1].add_x(x_vals)
        sketches[-1].add_y(y_vals)

        sketches.append(ScatterSketch())
        sketches[-1].add_x(list(self.training_x))
        sketches[-1].add_y(list(self.training_y))

        for i in range(len(self.training_x)):
            if self.f(self.training_x[i]) > self.training_y[i]:
                y_max = self.f(self.training_x[i])
                y_min = self.training_y[i]
            else:
                y_min = self.f(self.training_x[i])
                y_max = self.training_y[i]
            sketches.append(VerticalLineSketch())
            sketches[-1].set_y_max(y_max)
            sketches[-1].set_y_min(y_min)
            sketches[-1].set_x(self.training_x[i])

        plotter.load(sketches)
        plotter.save()
        plotter.close()

        image_manager.scale(g.files['least-squares'], g.files['least-squares'],
                            250)

        del plotter
        del image_manager
Ejemplo n.º 4
0
    def plot(self):
        plotter = Plotter()
        image_manager = ImageManager()
        sketches = []
        plotter.set_output_filename(g.files['logistic-regression'])
        plotter.set_title('Logistic Regression')
        g.debug.prn(self, 'Plot basics set.')

        min_x = min(self.training_x)
        max_x = max(self.training_x)
        min_y = min(self.training_y)
        max_y = max(self.training_y)
        x_vals = []
        y_vals = []
        for x in range(min_x * 100, max_x * 100):
            y_adjust = self.f(x / 100) * (max_y - min_y) + min_y
            x_vals.append([x / 100])
            y_vals.append([y_adjust])
        sketches.append(SmoothSketch())
        sketches[-1].add_x(x_vals)
        sketches[-1].add_y(y_vals)
        g.debug.prn(self, 'Curve added to sketches list.')

        sketches.append(ScatterSketch())
        sketches[-1].add_x(list(self.training_x))
        sketches[-1].add_y(list(self.training_y))
        g.debug.prn(self, 'Scatter of points added to sketches list.')

        plotter.load(sketches)
        plotter.save()
        plotter.close()
        g.debug.prn(self, 'All sketches loaded and saved.')

        image_manager.scale(g.files['logistic-regression'],
                            g.files['logistic-regression'], 250)

        del plotter
        del image_manager
        g.debug.prn(self, 'Plotter and ImageManager objects deleted', 3)
Ejemplo n.º 5
0
def gen_plot():
    plotter.set_title(g.graph_titles['main'])

    g.x = g.randomizer.random_list(25, 0, 100)
    g.y = g.randomizer.random_list(25, 0, 100)

    # plotter.add_x_val(x) # [-2, -1, 0, 1, 2]
    # plotter.add_y_val(y) # [4,1,0,1,4]

    scatter = ScatterSketch()
    scatter.add_x(g.x)
    scatter.add_y(g.y)
    plotter.load(scatter)

    plotter.save()
    plotter.close()

    # g.modeller.gen_least_squares(x,y)
    # g.analyzer.f_dist(LinearModel, 100)

    image_manager.scale(g.files['plot'], g.files['plot'], g.image_height)