We've prepared a dictionary vectorizer and a model.
They were trained (roughly) using this code:
features = ['reports', 'share', 'expenditure', 'owner'] dicts = df[features].to_dict(orient='records')
dv = DictVectorizer(sparse=False) X = dv.fit_transform(dicts)
model = LogisticRegression(solver='liblinear').fit(X, y)
Import the pickle package to save the model
First, install flask:
pip install flask
Run the service:
python credit_card.py
Test it from python:
import requests
url = 'http://localhost:9696/predict'
response = requests.post(url, json=customer)
result = response.json()
Install pipenv
:
pip install pipenv
Install the depencencies from the Pipfile:
pipenv install
Enter the pipenv virtual environment:
pipenv shell
And run the code:
python credit_card.py
Alternatively, you can do both steps with one command:
pipenv run python credit_card.py
Now you can use the same code for testing the model locally.
Build the image (defined in Dockerfile)
docker build -t credit-card-prediction .
Run it:
docker run -it -p 9696:9696 credit-card-prediction:latest