Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# Mac OS-specific storage files
.DS_Store

# vim
*.swp
*.swo

## https://github.com/github/gitignore/blob/4488915eec0b3a45b5c63ead28f286819c0917de/Python.gitignore

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# MkDocs documentation
docs/site/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
68 changes: 68 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#################################################################################
# GLOBALS #
#################################################################################

PROJECT_NAME = Lab-ML-platzi
PYTHON_VERSION = 3.10
PYTHON_INTERPRETER = python

#################################################################################
# COMMANDS #
#################################################################################


## Install Python Dependencies
.PHONY: requirements
requirements:
$(PYTHON_INTERPRETER) -m pip install -U pip
$(PYTHON_INTERPRETER) -m pip install -r requirements.txt




## Delete all compiled Python files
.PHONY: clean
clean:
find . -type f -name "*.py[co]" -delete
find . -type d -name "__pycache__" -delete

## Lint using flake8 and black (use `make format` to do formatting)
.PHONY: lint
lint:
flake8 logistic_regression
isort --check --diff --profile black logistic_regression
black --check --config pyproject.toml logistic_regression

## Format source code with black
.PHONY: format
format:
black --config pyproject.toml logistic_regression






#################################################################################
# PROJECT RULES #
#################################################################################



#################################################################################
# Self Documenting Commands #
#################################################################################

.DEFAULT_GOAL := help

define PRINT_HELP_PYSCRIPT
import re, sys; \
lines = '\n'.join([line for line in sys.stdin]); \
matches = re.findall(r'\n## (.*)\n[\s\S]+?\n([a-zA-Z_-]+):', lines); \
print('Available rules:\n'); \
print('\n'.join(['{:25}{}'.format(*reversed(match)) for match in matches]))
endef
export PRINT_HELP_PYSCRIPT

help:
@$(PYTHON_INTERPRETER) -c "${PRINT_HELP_PYSCRIPT}" < $(MAKEFILE_LIST)
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ curl --location --request GET 'http://localhost:3001/query?feats=465,France,Fema

Si todo esta bien, deberías de obtener una respuesta así
```
{"response": [1]}
{"response": [0]}
```

#### Equipo

* Juan Perez Nombrefalso
* Ricardo Alanís Tamez
* Angel Martínez

#### Contribuir

Expand Down
34 changes: 29 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@
import pandas as pd


FEATURES = pickle.load(open("churn/models/features.pk", "rb"))
# Cargar las características, el modelo y las equivalencias de columnas desde archivos creados con la libreria pickle
FEATURES = pickle.load(open("models/features.pk", "rb"))
model = pickle.load(open("models/model.pk", "rb"))
column_equivalence = pickle.load(open("models/column_equivalence.pk", "rb"))

model = pickle.load(open("churn/models/model.pk", "rb"))
column_equivalence = pickle.load(open("churn/models/column_equivalence.pk", "rb"))

# create the Flask app
app = Flask(__name__)

def convert_numerical(features):
"""
Función para convertir características en formato numérico.

Si una característica es categórica, se reemplaza por su código numérico
utilizando el diccionario 'column_equivalence'. Si no es categórica,
se intenta convertir a valor numérico con pandas. Si falla, se coloca un 0.

Parámetros:
features (list): Lista de características a convertir.

Retorna:
list: Lista de características convertidas a formato numérico.
"""
output = []
for i, feat in enumerate(features):
if i in column_equivalence:
Expand All @@ -26,12 +39,23 @@ def convert_numerical(features):

@app.route('/query')
def query_example():
"""
Endpoint que recibe características en la URL, las convierte a formato numérico
y devuelve la predicción del modelo en formato JSON.

Parámetros (GET):
feats: Cadena de características separadas por comas.

Retorna:
JSON: Respuesta con la predicción del modelo.
"""

features = convert_numerical(request.args.get('feats').split(','))
response = {
'response': [int(x) for x in model.predict([features])]
}
return json.dumps(response)

if __name__ == '__main__':
# run app in debug mode on port 3001
# Ejecutamos la aplicación Flask en modo debug en el puerto 3001
app.run(debug=True, port=3001)
Binary file removed churn/.DS_Store
Binary file not shown.
Binary file removed churn/models/column_equivalence.pk
Binary file not shown.
Binary file removed churn/models/features.pk
Binary file not shown.
Binary file removed churn/models/model.pk
Binary file not shown.
Binary file removed data/.DS_Store
Binary file not shown.
Empty file added data/processed/.gitkeep
Empty file.
Empty file added data/raw/.gitkeep
Empty file.
File renamed without changes.
Empty file added docs/.gitkeep
Empty file.
Binary file added models/column_equivalence.pk
Binary file not shown.
Binary file added models/features.pk
Binary file not shown.
Binary file added models/model.pk
Binary file not shown.
Loading