28
Implementing Machine Learning steps using Regression Model.
From our previous article we looked at the machine learning steps. Lets now have a look at how to implement a machine learning model using Python.
The dataset used is collected from kaggle.
We will be able to predict the insurance amount for a person.
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import accuracy_score
data=pd.read_csv('insurance.csv')
data

label=LabelEncoder()
label.fit(data.sex.drop_duplicates())
data.sex=label.transform(data.sex)
label.fit(data.smoker.drop_duplicates())
data.smoker=label.transform(data.smoker)
label.fit(data.region.drop_duplicates())
data.region=label.transform(data.region)
data
X=data.drop(['charges'], axis=1)
y=data[['charges']]
X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.33, random_state=42)
model=LinearRegression())
model.fit(X_train,y_train)



28