This project aim to implement a clustering algorythm (’K-Means’) in order to get valuable insights, data comes from Kaggle and is related to chemical composition of wines. For more information on the clustering and what it represents, I suggest reviewing the notebook.
Before getting started keep in mind the tools used to develop this project were the following:
-
Clone the Github repository
-
Open Docker Desktop, if you don’t have it, go here
-
Run the following command to build and run the Docker container
docker-compose up --build
-
At this point the API should be running and accesible at port 5000
There are different ways to test an API, you can use tools such as Postman where you testing can be done without even write a line of code, but, if you prefer to make the requests using Python, here’s some examples:
The following code will return you a JSON with all the data, if an error occurs make sure you do not have any service running on the port 5000
import requests
url = 'http://localhost:5000/'
try:
response = requests.get(url)
response.raise_for_status()
data = response.json()
print(data)
except requests.exceptions.RequestException as e:
print("Error:", e)
The following code will return you a dictionary with the min and max value from each attribute
import requests
url = 'http://localhost:5000/ranges'
try:
response = requests.get(url)
response.raise_for_status()
data = response.json()
print(data)
except requests.exceptions.RequestException as e:
print("Error:", e)
The following code will provide you with a JSON containing all the data associated with cluster 1
import requests
url = 'http://localhost:5000/cluster1'
try:
response = requests.get(url)
response.raise_for_status()
data = response.json()
print(data)
except requests.exceptions.RequestException as e:
print("Error:", e)
import requests
url = 'http://localhost:5000/cluster2'
try:
response = requests.get(url)
response.raise_for_status()
data = response.json()
print(data)
except requests.exceptions.RequestException as e:
print("Error:", e)
import requests
url = 'http://localhost:5000/cluster3'
try:
response = requests.get(url)
response.raise_for_status()
data = response.json()
print(data)
except requests.exceptions.RequestException as e:
print("Error:", e)
If you have any questions or suggestions, feel free to contact me at [email protected]