Linear Regression in Python
Yes, you will have to convert everything to numeric. That requires thinking about what these attributes represent accordingly you can use either the below 3 options.

There are three options:


One-Hot encoding for categorical data
Arbitrary numbers for ordinal data
Use something like group means for categorical data (e. g. mean
prices for city districts).


You have to be careful to not infuse information you do not have in the application case.

I'm expanding on option 1 and 3, if you want to know about option 2 you can go through the links attached at last.

One hot encoding

If you have categorical data, you can create dummy variables with 0/1 values for each possible value. Similarly you could implement for children, smoker.

E. g.

id  Sex
0   Male
1   Feamle


to

id   Male   Female 
0      1       0    
1      0       1   


This can easily be done with pandas:

import pandas as pd

data = pd.DataFrame({'Sex': ['Male', 'Female']})
print(pd.get_dummies(data))


will result in:

        Sex_Male  Sex_Female 
0           1            0         
1           0            1        


Using categorical data for groupby operations

This is an additional usecase but in your case it is not necessary to use this but if you feel so, you can try implementing this as well

You could use the mean for each category over past (known events).

Say you have a DataFrame with the last known mean prices for cities:

prices = pd.DataFrame({
    'city': ['A', 'A', 'A', 'B', 'B', 'C'],
    'price': [1, 1, 1, 2, 2, 3],
})
mean_price = prices.groupby('city').mean()
data = pd.DataFrame({'city': ['A', 'B', 'C', 'A', 'B', 'A']})

print(data.merge(mean_price, on='city', how='left'))


Result:

  city  price
0    A      1
1    B      2
2    C      3
3    A      1
4    B      2
5    A      1


For better understanding you can go through this Link-1, Link-2