Math for Data Science Chapter 5 Linear Regression

Linear Regression

Attempting to fit a function (a straight line) to a dataset to observe a linear relationship. Then used to predict further values given the line that we’ve fit.

Validation

Machine Learning engineers will use train-test splits, which means that they will split up the data into a train and a test set. Statisticians will use metrics, prediction intervals and correlations.kjA

Unsupervised learning

Regression is supervised (requires examples to calculate the line), but unsupervised learning is all about anomaly detection and clustering.

Linear Correlation

As one variable increases or decreases, another variable does as well. This is the backbone of the technique is trying to find a relationship like this.

Benefits and Drawbacks of Linear Regression

Benefits

  1. Can make predictions on unseen data. The line gives us that ability.

Drawbacks

  1. Real-world data is not always linear.
  2. There will be error about the line.
  3. We cannot predict reliably outside of our range of values.

Considering sampling bias

The data may be skewed, given some bias of the sample. The data are usually a sample from a population and never indicative of the entire population itself, so ensure that you take that into account.

Performing a basic linear regression in Julia

First, we require some basic packages to support our work, change the the package mode with ] in the REPL and add some packages:

  1. DataFrames
  2. CSV
module chapter5

using DataFrames
using CSV
using Downloads
using Plots
using Flux

function example51()
    # First download the file.
    dataset = Downloads.download("https://bit.ly/3goOAnt")

    # Then read the file into a DataFrame
    df = DataFrame(CSV.File(dataset))

    # Extract our values with dataframe indexing.
    X = df[:, 1:end-1]
    Y = df[:, end]

    # Fit a linear regression - https://fluxml.ai/Flux.jl/stable/models/overview/
    model = Dense(1 => 1) # One input variable, one output variable
    # TO BE CONTINUED
end

end

 Share!

 
I run WindleWare! Feel free to reach out!

Subscribe for Exclusive Updates

* indicates required