Skip to content

Instantly share code, notes, and snippets.

@hackintoshrao
Created January 29, 2017 02:32
Show Gist options
  • Select an option

  • Save hackintoshrao/49b5c45ae567632d00b4727fbaddeabc to your computer and use it in GitHub Desktop.

Select an option

Save hackintoshrao/49b5c45ae567632d00b4727fbaddeabc to your computer and use it in GitHub Desktop.
Doing linear regression using python.
# TODO: Add import statements
import pandas as pd
from sklearn import linear_model
# Assign the dataframe to this variable.
# TODO: Load the data
bmi_life_data = pd.read_csv("bmi_and_life_expectancy.csv")
# Make and fit the linear regression model
#TODO: Fit the model and Assign it to bmi_life_model
bmi_life_model = linear_model.LinearRegression()
bmi_life_model.fit(bmi_life_data[['BMI']],bmi_life_data[['Life expectancy']])
# Mak a prediction using the model
# TODO: Predict life expectancy for a BMI value of 21.07931
laos_life_exp = bmi_life_model.predict(21.07931)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment