Member-only story

Linear regression in R for busy developers

Rabin Poudyal
2 min readDec 9, 2019

(Sometimes simple model like linear regression can also win the war of machine learning algorithm)

linear regression

Since the title speaks for busy developers, I don’t want to write any boring introduction. Fire up your Rstudio and let’s get started.

Download dataset from here

Step 1: Load the dataset

Step 2: Create a linear model

Assumption:

BMI(independent variable): Body mass index

charges(dependent variable): Charges depend on BMI

(Note: this is only my assumption for this article that charges are dependent on BMI.)

building a linear model

Step 3: Visualize what you did

Execute the following code to visualize your plot:

plot(select_dataframe, col="blue")
plotting charges vs bmi

Cool! Now let’s draw that regression line we were waiting for. Execute the following command to draw a linear line above the graph shown above.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Rabin Poudyal
Rabin Poudyal

Written by Rabin Poudyal

Software Engineer, Data Science Practitioner. Say "Hi!" via email: rabinpoudyal1995@gmail.com or visit my website https://rabinpoudyal.com.np

No responses yet

Write a response