def createScatterPlot(name,x,y):
    """Creates scatter plot

        Args:
            name(str): name of value being plotted against MPG
            x(list): list of values used for the x-axis
            y(list): list of values used for the y-axis

        Notes:
            Used in AutoData.ipynb
    """
    
    #Calculate slope
    m, b = utils.compute_slope_intercept(x,y)
    
    #Use matplotlib to create histogram
    plt.figure()
    plt.scatter(x,y)
    plt.plot([min(x), max(x)], [m*min(x)+b, m*max(x)+b], c="r",lw=5)
    
    #Create title
    plt.title("{} vs. MPG Scatter Plot".format(name))
    plt.xlabel(name)
    plt.ylabel("MPG")
    
    #Annotate
    #Calculate correlation coefficient
    corrCoeff = utils.calculateCorrCoeff(x,y)
    plt.annotate("$corCoef = {}$".format(str(corrCoeff)),xy=(.85,.9),xycoords="axes fraction", horizontalalignment="center",color="blue")
    #Calculate covariance
    covariance = utils.calculateCovariance(x,y)
    plt.annotate("$cov = {}$".format(str(covariance)),xy=(.85,.8),xycoords="axes fraction", horizontalalignment="center",color="blue")
    
    #Show Diagram
    plt.show()
def movieScatterPlot(x_title,x,y_title,y):
    """Creates scatter plot for movies data.

        Args:
            x_title(str): name of values on x-axis
            x(list): list of x-axis values
            y_title(str): name of values on y-axis
            y(list): list of y-axis values

        Notes:
            Used in Movies.ipynb
    """
    
    #Remove percentages
    x = utils.removePercentage(x)
    y = utils.removePercentage(y)
    
    #Calculate slope
    m, b = utils.compute_slope_intercept(x,y)
    
    #Use matplotlib to create histogram
    plt.figure() #figsize=(10,10))
    plt.scatter(x,y)
    plt.plot([min(x), max(x)], [m*min(x)+b, m*max(x)+b], c="r",lw=5)
    
    #Create labels
    plt.title("{} vs. {} Scatter Plot".format(x_title,y_title))
    plt.xlabel("{} Ratings".format(x_title))
    plt.ylabel("{} Ratings".format(y_title))
    
    #Show Diagram
    plt.show()
Esempio n. 3
0
 def fit(self, X_train, y_train):
     """Fits a simple linear regression line to X_train and y_train.
     Args:
         X_train(list of list of numeric vals): The list of training samples
             The shape of X_train is (n_train_samples, n_features)
             Note that n_features for simple regression is 1, so each sample is a list 
                 with one element e.g. [[0], [1], [2]]
         y_train(list of numeric vals): The target y values (parallel to X_train) 
             The shape of y_train is n_train_samples
     """
     x = myutils.convert_2D_to_1D(X_train)
     y = myutils.convert_2D_to_1D(y_train)
     slope, intercept = myutils.compute_slope_intercept(x, y_train)
     self.slope = slope 
     self.intercept = intercept
Esempio n. 4
0
    def fit(self, X_train, y_train):
        """Fits a simple linear regression line to X_train and y_train.

        Args:
            X_train(list of list of numeric vals): The list of training samples
                The shape of X_train is (n_train_samples, n_features)
                Note that n_features for simple regression is 1, so each sample is a list 
                    with one element e.g. [[0], [1], [2]]
            y_train(list of numeric vals): The target y values (parallel to X_train) 
                The shape of y_train is n_train_samples
        """
        x_train_1d = []
        for sample in X_train:
            x_train_1d.append(sample[0])
        m, b = myutils.compute_slope_intercept(x_train_1d, y_train)
        self.slope = m
        self.intercept = b