-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_3.py
68 lines (56 loc) · 1.92 KB
/
main_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from fastapi import FastAPI
from pydantic import BaseModel
from enum import Enum
import joblib
import pandas as pd
import uvicorn
# 모델 로드
model1 = joblib.load('loanlimit_model.pkl')
app = FastAPI()
class LoanApplication(BaseModel):
birth_year : float
gender : float
credit_score : float
yearly_income : float
company_enter_month : float
existing_loan_cnt : float
existing_loan_amt : float
personal_rehabilitation_ing : int
personal_rehabliltation_done : int
한국은행_기준금리 : float
pc1 : float
income_type_EARNEDINCOME2 : bool
income_type_FREELANCER : bool
income_type_OTHERINCOME : bool
income_type_PRACTITIONER : bool
income_type_PRIVATEBUSINESS : bool
employment_type_기타 : bool
employment_type_일용직 : bool
employment_type_정규직 : bool
houseown_type_배우자 : bool
houseown_type_자가 : bool
houseown_type_전월세 : bool
purpose_BUYCAR : bool
purpose_HOUSEDEPOSIT : bool
purpose_기타 : bool
purpose_대환대출 : bool
purpose_사업자금 : bool
purpose_생활비 : bool
purpose_자동차구입 : bool
purpose_전월세보증금 : bool
purpose_주택구입 : bool
purpose_투자 : bool
class predict_output(BaseModel):
predicted_loan_limit : float
@app.post("/predict_loan_limit", response_model=predict_output)
def predict_loan_limit(application: LoanApplication):
# 입력 데이터를 DataFrame으로 변환
input_df = pd.DataFrame([dict(application)])
# "한국은행_기준금리"를 "한국은행 기준금리"로 변경
input_df.rename(columns={"한국은행_기준금리": "한국은행 기준금리"}, inplace=True)
# 예측 수행
prediction = model1.predict(input_df)
# 예측 결과 반환
return {"predicted_loan_limit": prediction[0]}
if __name__ == "__main__":
uvicorn.run("main_3:app", host = '0.0.0.0', port=80, reload = True)