Reading-Notes

View the Project on GitHub MohammadAl-khatib/Reading-Notes

Linear Regressions

Is the prediction of how two variables are related to each other, in Python you need a data frame to start working on linear regression, eighther it is already there, or you need to create your own data frame using Pandas, assuming data frame is ready and contains the required parameters; do the following steps to have a linear regression model:

  1. Import LinearRegression from sk.linear_model
  2. Drop any value that you don’t want to appear on the x-axis
  3. Store linear regression inside a variable:
    • variable = LinearRegression()
    • Linear regression contains some important functions
      • lm.fit() -> fits a linear model
      • lm.predict() -> Predict Y using the linear model with estimated coefficients
      • lm.score() -> Returns the coefficient of determination (R^2)
      • .coef_ gives the coefficients
      • .intercept_ gives the estimated intercepts.
  4. Use lm.fit(), the first argument is the x-axis data, the second is the y-axis data
  5. Use LinearRegression(copy_X=True, fit_intercept=True, normalize=False)
  6. Construct a data frame that contains features and estimated coefficients
  7. Notice any feature that has a high estimated coefficient
  8. Use plot to plot that feature against the y-axis of step 4

Example plot:

LINEAR REGRESSION

Resources: bigdata-madesimple