# Import NumPy and matplotlib.pyplot
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
# Read in the data for age, bmi and insurance charges in separate arrays.
# Print out to check
filename='insurance.csv'
age=np.loadtxt(filename,usecols=0,delimiter=',',skiprows=1)
print(age)
bmi=np.loadtxt(filename,usecols=2,delimiter=',',skiprows=1)
print(bmi)
charges=np.loadtxt(filename,usecols=6,delimiter=',',skiprows=1)
print(charges)
# print out the number of data instances
print(len(age))
# plot charges vs age and add labels to axis and title
plt.scatter(age,charges)
plt.xlabel('Age')
plt.ylabel('Charges')
# plot charges vs BMI; add axis labels and plot title
plt.scatter(bmi,charges)
plt.xlabel('BMI')
plt.ylabel('Charges')
# Import NumPy and matplotlib.pyplot
import numpy as np
import matplotlib.pyplot as plt
# Read in the data for bmi and insurance charges in separate arrays.
# Print out to check
#
filename='insurance.csv'
bmi=np.loadtxt(filename,usecols=2,delimiter=',',skiprows=1)
print(bmi)
charges=np.loadtxt(filename,usecols=6,delimiter=',',skiprows=1)
print(charges)
# Fit a line using linear regression
coeff=np.polyfit(bmi,charges,1)
f = np.poly1d(coeff)
print(coeff)
# Plot data and line on same graph
plt.plot(bmi,charges,'ro')
bmi_min=np.min(bmi)
bmi_max=np.max(bmi)
xx=np.linspace(bmi_min,bmi_max,2)
yy=f(xx)
plt.plot(xx,yy,'b')
plt.show()
# Fit a parabola to data
parab_coeff=np.polyfit(bmi,charges,2)
g = np.poly1d(parab_coeff)
# Plot data and parabola on same graph
plt.plot(bmi,charges,'ro')
xxx=np.linspace(bmi_min,bmi_max)
yyy=g(xxx)
plt.plot(xxx,yyy,'b')
plt.plot()