In [40]:
%matplotlib inline
import pandas as pd
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
In [41]:
# Assign the dataframe to this variable.
bmi_life_data = pd.read_csv("bmi_and_life_expectancy.csv")
x_values = bmi_life_data[['BMI']]
y_values = bmi_life_data[['Life expectancy']]
In [42]:
#print(bmi_life_data)
In [43]:
# Make and fit the linear regression model
#TODO: Fit the model and Assign it to bmi_life_model
bmi_life_model = LinearRegression()
bmi_life_model.fit(x_values,y_values)
Out[43]:
In [44]:
# 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)
In [45]:
print(laos_life_exp)
In [47]:
#visualize results
plt.scatter(x_values, y_values)
plt.plot(x_values, bmi_life_model.predict(x_values))
plt.show()