Insurance Prediction in Logistic Regression in Machine Learning

Free Machine Learning courses with 130+ real-time projects Start Now!!

Program 1

import pandas as pd
import numpy as np
from matplotlib import pyplot as plt


df=pd.read_csv("D://scikit_data/insurancedata/insurance_data.csv")


df.head(10)


plt.scatter(df.age,df.bought_insurance,marker='*',color='blue')
plt.show()


from sklearn.model_selection import train_test_split


x_train,x_test,y_train,y_test=train_test_split(df[['age']],df.bought_insurance,test_size=0.1)

len(x_train)


x_train


len(x_test)


x_test


from sklearn.linear_model import LogisticRegression



model=LogisticRegression()


model.fit(x_train,y_train)


model.predict(x_test)


model.score(x_test,y_test)


model.score(x_train,y_train)


model.predict([[87]])


n=int(input("Enter age: "))
x=model.predict([[n]])
if(x==[1]):
    print("Purchase")
else:
    print("Not Purchase")


x_test



model.predict_proba(x_test)

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *