Data Analysis

Medical Insurance 비용 변화 분석 - Python(리스트 활용)

hyungminjeon 2025. 4. 9. 10:12

 

이번 프로젝트에서는 리스트(list)와 zip() 함수를 활용하여 보험료를 분석하는 방식을 개선하였다.
특정 개인의 예상 보험 비용을 계산한 후, 실제 보험 비용과 비교하는 기능을 추가하였다.

 

1. 보험 비용 계산 함수 (estimate_insurance_cost)

먼저, 보험 비용을 예측하는 함수를 정의하였다.

def estimate_insurance_cost(name, age, sex, bmi, num_of_children, smoker):
    estimated_cost = 250 * age - 128 * sex + 370 * bmi + 425 * num_of_children + 24000 * smoker - 12500
    print(name + "'s Estimated Insurance Cost: " + str(estimated_cost) + " dollars.")
    return estimated_cost

함수 설명

  • 입력값
    • name: 이름
    • age: 나이
    • sex: 성별 (0 = 여성, 1 = 남성)
    • bmi: 체질량지수(BMI)
    • num_of_children: 자녀 수
    • smoker: 흡연 여부 (0 = 비흡연자, 1 = 흡연자)
estimated_cost = 250 * age - 128 * sex + 370 * bmi + 425 * num_of_children + 24000 * smoker - 12500
  • 수식 해석 
    • 나이가 많을수록 보험료 증가
    • 남성(sex = 1)의 경우 보험료 감소 (-128 적용)
    • BMI(체질량지수)가 높을수록 보험료 증가
    • 자녀 수가 많을수록 보험료 증가
    • 흡연자의 경우 보험료가 크게 증가 (+24,000)
    • 기본 비용(-12,500) 설정

2. 개별 보험료 예측 실행

# Estimate Maria's insurance cost
maria_insurance_cost = estimate_insurance_cost(name="Maria", age=31, sex=0, bmi=23.1, num_of_children=1, smoker=0)

# Estimate Rohan's insurance cost
rohan_insurance_cost = estimate_insurance_cost(name="Rohan", age=25, sex=1, bmi=28.5, num_of_children=3, smoker=0)

# Estimate Valentina's insurance cost
valentina_insurance_cost = estimate_insurance_cost(name="Valentina", age=53, sex=0, bmi=31.4, num_of_children=0, smoker=1)

위 코드를 실행하면 각각의 예상 보험 비용이 출력된다.
Maria, Rohan, Valentina에 대한 보험료가 계산되었으며, 이후 실제 보험료와 비교하는 과정을 진행한다.


3. 실제 보험료 데이터 저장

보험사에서 제공한 실제 보험료 데이터를 리스트에 저장하였다.

names = ["Maria", "Rohan", "Valentina"]

# 실제 보험료 리스트
insurance_costs = [4150.0, 5320.0, 35210.0]

# 리스트를 튜플 형태로 변환
insurance_data = list(zip(names, insurance_costs))

print("Here is the actual insurance cost data: " + str(insurance_data))

zip() 함수 활용

  • names 리스트와 insurance_costs 리스트를 zip() 함수로 결합하여 각 사람의 실제 보험료를 튜플 형태로 저장하였다.
  • list(zip(names, insurance_costs)) → [("Maria", 4150.0), ("Rohan", 5320.0), ("Valentina", 35210.0)]

실행 결과:

Here is the actual insurance cost data: [('Maria', 4150.0), ('Rohan', 5320.0), ('Valentina', 35210.0)]

4. 예상 보험료 데이터 저장

앞서 계산한 예상 보험료를 리스트에 저장하였다.

estimated_insurance_data = []
estimated_insurance_data.append(("Maria", maria_insurance_cost))
estimated_insurance_data.append(("Rohan", rohan_insurance_cost))
estimated_insurance_data.append(("Valentina", valentina_insurance_cost))

print("Here is the estimated insurance cost data: " + str(estimated_insurance_data))
  • 빈 리스트 estimated_insurance_data를 생성한 후, append()를 이용해 예상 보험료 데이터를 추가하였다.
  • ("Maria", maria_insurance_cost), ("Rohan", rohan_insurance_cost), ("Valentina", valentina_insurance_cost) 형태의 튜플을 리스트에 저장하였다.

실행 결과:

Here is the estimated insurance cost data: [('Maria', 4250.0), ('Rohan', 7655.0), ('Valentina', 37378.0)]

5. 결과 비교

이제 실제 보험료 데이터와 예상 보험료 데이터를 비교할 수 있다.

실제 보험료예상 보험료차이

 

Maria 4150.0 4222.0 +72.0
Rohan 5320.0 5442.0 +122.0
Valentina 35210.0 36368.0 +1158.0
  • 예상 보험료가 실제 보험료와 비교적 유사하게 계산되었지만, 일부 오차가 발생하였다.
  • 추가적인 변수(운동 습관, 건강 상태 등)를 반영하면 더 정밀한 보험료 예측 모델을 만들 수 있다.

6. 결론

이번 프로젝트에서는 리스트와 zip() 함수를 활용하여 보험료 데이터를 체계적으로 저장하고 비교하는 방법을 학습하였다.

개선된 점

  1. 리스트를 활용한 데이터 구조화
    • 여러 개의 보험료 데이터를 리스트에 저장하여 데이터 분석이 용이해짐
  2. zip()을 이용한 데이터 결합
    • zip()을 사용하여 이름과 보험료 데이터를 한 번에 저장
  3. 실제 보험료와 비교 기능 추가
    • 예측 결과를 실제 데이터와 비교하여 모델의 정확도를 평가할 수 있음

앞으로 추가적인 요소를 반영하여 보험료 예측 모델을 더욱 정교하게 발전시킬 수 있을 것이다.