/Univariate-Linear-Regression

Implementing the gradient descent algorithm from scratch to perform univariate linear regression to analyze the profit made by a bike sharing company.

Primary LanguageJupyter Notebook

Univariate-Linear-Regression

Problem statement

Linear Regression is implemented to identify the relationship between profit of a bike sharing company and population of different cities. The main objective is to find the next city in which a new outlet should be opened which results in optimal profitability.

Data visualization

data_plot

Implementation

  • Application of the cost function as shown below:
    cost_function_formula

  • Visualization of the cost function by plotting the cost over a 2-dimensional grid of 𝜃_0 and 𝜃_1 values. The cost function J(𝜃) is bowl-shaped and has a global minimum.
    cost_function_3D

  • Implementation of gradient descent algorithm from scratch in Python without the use of machine learning frameworks such as scikit-learn and statsmodels. Ran the algorithm over 2000 iterations to minimize the cost J(θ). With each step of batch gradient descent, the parameters 𝜃_j come closer to the optimal values that will achieve the lowest cost J(𝜃). The plot of convergence is shown below:
    gradient_descent

Results

Univariate Linear Regression Fit:

line_of_bestfit

Libraries used

  • matplotlib
  • numpy
  • pandas
  • seaborn
  • mpl_toolkits

References