Example #1
0
    def test_linear_regression(self):
        initial_theta = np.ones(self.n + 1)
        lamda = 0.0
        theta = train_linear_reg(initial_theta, self.X, self.y, lamda)
        hypo = predictions(theta, self.X)

        # now scatter the data and plot the hypothesis
        plt.xlabel("Change in water level (x)")
        plt.ylabel("Water flowing out of the dam (y)")
        plt.scatter(self.X, self.y, marker='x', c='r', s=30, linewidth=2)
        plt.plot(self.X, hypo)
        plt.show()
Example #2
0
 def test_linear_regression(self):
     initial_theta = np.ones(self.n+1)
     lamda = 0.0
     theta = train_linear_reg(initial_theta, self.X, self.y, lamda)
     hypo = predictions(theta, self.X)
     
     # now scatter the data and plot the hypothesis
     plt.xlabel("Change in water level (x)")
     plt.ylabel("Water flowing out of the dam (y)")
     plt.scatter( self.X, self.y, marker='x', c='r', s=30, linewidth=2 )
     plt.plot( self.X, hypo )
     plt.show()
Example #3
0
 def test_linear_regression_poly(self):
     highest_degree = 8
     X_poly = map_poly_features(self.X, highest_degree)
     X_poly, mu, sigma = feature_normalization(X_poly)
     
     initial_theta = np.ones(highest_degree+1)
     lamda = 0.0
     theta = train_linear_reg(initial_theta, X_poly, self.y, lamda)
     hypo = predictions(theta, X_poly)
     
     # now scatter the data and plot the hypothesis
     df = pd.DataFrame(np.hstack(( self.X, hypo.reshape(self.y.shape), self.y )), columns=['X','hypo','y'])
     df = df.sort('X')
     plt.xlabel("Change in water level (x)")
     plt.ylabel("Water flowing out of the dam (y)")
     plt.scatter( df['X'], df['y'], marker='x', c='r', s=30, linewidth=2 )
     plt.plot( df['X'], df['hypo'], linestyle='--', linewidth=3 )
     plt.show()
Example #4
0
    def test_linear_regression_poly(self):
        highest_degree = 8
        X_poly = map_poly_features(self.X, highest_degree)
        X_poly, mu, sigma = feature_normalization(X_poly)

        initial_theta = np.ones(highest_degree + 1)
        lamda = 0.0
        theta = train_linear_reg(initial_theta, X_poly, self.y, lamda)
        hypo = predictions(theta, X_poly)

        # now scatter the data and plot the hypothesis
        df = pd.DataFrame(np.hstack(
            (self.X, hypo.reshape(self.y.shape), self.y)),
                          columns=['X', 'hypo', 'y'])
        df = df.sort('X')
        plt.xlabel("Change in water level (x)")
        plt.ylabel("Water flowing out of the dam (y)")
        plt.scatter(df['X'], df['y'], marker='x', c='r', s=30, linewidth=2)
        plt.plot(df['X'], df['hypo'], linestyle='--', linewidth=3)
        plt.show()