kothariyashhh's picture
Upload 7 files
60434a7 verified
# predict_model.py
import pandas as pd
import joblib
# predict_model.py
import pandas as pd
import joblib
class InsuranceClaimPredictor:
def __init__(self, model_path):
self.model_path = model_path
self.model = self.load_model()
def load_model(self):
# Load the model
loaded_model = joblib.load(self.model_path)
return loaded_model
def predict(self, data):
# Make predictions
predictions = self.model.predict(data)
return predictions
if __name__ == "__main__":
predictor = InsuranceClaimPredictor('model/insurance_claim_prediction_model.joblib')
# # Example of a person who is less likely to make an insurance claim
# unseen_data_non_claim = pd.DataFrame({
# 'age': [25], # Younger age
# 'sex': ['female'], # Female (just an example, gender may not significantly affect the outcome)
# 'bmi': [22.0], # Lower BMI
# 'children': [0], # No children
# 'smoker': ['no'], # Non-smoker
# 'region': ['southwest'], # Region (doesn't typically affect claims, chosen arbitrarily)
# 'charges': [1000] # Lower medical expenses
# })
# predictions = predictor.predict(unseen_data_non_claim)
# print("Predictions for the unseen data:", predictions)
#Example of how to use the function
unseen_data = pd.DataFrame({
'age': [40],
'sex': ['male'],
'bmi': [25.3],
'children': [2],
'smoker': ['no'],
'region': ['southeast'],
'charges': [2900]
})
predictions = predictor.predict(unseen_data)
print("Predictions for the unseen data:", predictions)