Commit 50bc0a3f authored by Anuththara18's avatar Anuththara18

Deployment Files Added

parent 2f97837c
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "bcdc5589",
"metadata": {},
"outputs": [],
"source": [
"# importing libraries \n",
"import numpy as nm \n",
"import matplotlib.pyplot as mtp \n",
"import pandas as pd \n",
"from sklearn.cluster import DBSCAN\n",
"from numpy import unique\n",
"from numpy import where\n",
"from matplotlib import pyplot"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f448f999",
"metadata": {},
"outputs": [],
"source": [
"# Importing the dataset \n",
"dataset = pd.read_csv('A4.csv') \n",
"dataset.drop(dataset.index[dataset['game'] == 'Focused'], inplace = True)\n",
"dataset.drop(dataset.index[dataset['game'] == 'Sustained'], inplace = True)\n",
"\n",
"dataset.drop(dataset.index[dataset['game'] == 'Alternating'], inplace = True)\n",
"dataset.drop(dataset.index[dataset['game'] == 'Selective'], inplace = True)\n",
"display(dataset)\n",
"# statistics of the data\n",
"dataset.describe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12841129",
"metadata": {},
"outputs": [],
"source": [
"# extracting only 11-comission & 12-omission\n",
"x = dataset.iloc[:, [18, 19]].values \n",
"display(x)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d569e05b",
"metadata": {},
"outputs": [],
"source": [
"# standardizing the data\n",
"from sklearn.preprocessing import StandardScaler\n",
"scaler = StandardScaler()\n",
"x = scaler.fit_transform(x)\n",
"\n",
"# statistics of scaled data\n",
"pd.DataFrame(x).describe()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "58284e31",
"metadata": {},
"outputs": [],
"source": [
"# Finding the optimal number of clusters using the elbow method\n",
"from sklearn.cluster import KMeans \n",
"wcss_list= [] #Initializing the list for the values of WCSS \n",
" \n",
"#Using for loop for iterations from 1 to 10. \n",
"for i in range(1, 11): \n",
" kmeans = KMeans(n_clusters=i, init='k-means++', random_state= 42) \n",
" kmeans.fit(x) \n",
" wcss_list.append(kmeans.inertia_) \n",
"mtp.plot(range(1, 11), wcss_list) \n",
"mtp.title('The Elobw Method Graph') \n",
"mtp.xlabel('Number of clusters(k)') \n",
"mtp.ylabel('wcss_list') \n",
"mtp.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5d1c61bf",
"metadata": {},
"outputs": [],
"source": [
"#training the K-means model on a dataset \n",
"kmeans = KMeans(n_clusters=3, init='k-means++', random_state= 42) \n",
"y_predict= kmeans.fit_predict(x) \n",
"print(y_predict)\n",
"\n",
"#visulaizing the clusters \n",
"mtp.scatter(x[y_predict == 0, 0], x[y_predict == 0, 1], s = 100, c = 'blue', label = 'Cluster 1') #for first cluster \n",
"mtp.scatter(x[y_predict == 1, 0], x[y_predict == 1, 1], s = 100, c = 'green', label = 'Cluster 2') #for second cluster \n",
"mtp.scatter(x[y_predict== 2, 0], x[y_predict == 2, 1], s = 100, c = 'red', label = 'Cluster 3') #for third cluster \n",
"mtp.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s = 300, c = 'yellow', label = 'Centroid') \n",
"mtp.title('Clusters of children') \n",
"mtp.xlabel('Commission Errors') \n",
"mtp.ylabel('Omission Errors') \n",
"mtp.legend() \n",
"mtp.show() "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2e691585",
"metadata": {},
"outputs": [],
"source": [
"new_df = dataset.iloc[:, [18, 19]].copy()\n",
"new_df['clusters'] = y_predict\n",
"new_df.head()\n",
"display(new_df)"
]
},
{
"cell_type": "markdown",
"id": "900a0d3f",
"metadata": {},
"source": [
"# Cluster Analysis"
]
},
{
"cell_type": "markdown",
"id": "262e8a4f",
"metadata": {},
"source": [
"## Cluster 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ba8fef3b",
"metadata": {},
"outputs": [],
"source": [
"len(new_df[new_df[\"clusters\"] == 0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "849d9447",
"metadata": {},
"outputs": [],
"source": [
"cluster_0 = new_df[new_df[\"clusters\"] == 0 ]\n",
"\n",
"maxVal = cluster_0['CER'].max()\n",
"minVal = cluster_0['CER'].min()\n",
"\n",
"print(\"CER min - \", minVal)\n",
"print(\"CER max - \", maxVal)\n",
"print()\n",
"\n",
"maxVal = cluster_0['OER'].max()\n",
"minVal = cluster_0['OER'].min()\n",
"\n",
"print(\"OER min - \", minVal)\n",
"print(\"OER max - \", maxVal)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6c5b7397",
"metadata": {},
"outputs": [],
"source": [
"cluster_0 = new_df[new_df[\"clusters\"] == 0 ]\n",
"display(cluster_0)\n",
"cluster_0.boxplot(column =['CER'], grid = False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c98d3f7e",
"metadata": {},
"outputs": [],
"source": [
"cluster_0.boxplot(column =['OER'], grid = False)"
]
},
{
"cell_type": "markdown",
"id": "dd8d7e4f",
"metadata": {},
"source": [
"## Cluster 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f9ed816e",
"metadata": {},
"outputs": [],
"source": [
"len(new_df[new_df[\"clusters\"] == 1])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ab1bc45",
"metadata": {},
"outputs": [],
"source": [
"cluster_1 = new_df[new_df[\"clusters\"] == 1 ]\n",
"\n",
"maxVal = cluster_1['CER'].max()\n",
"minVal = cluster_1['CER'].min()\n",
"\n",
"print(\"CER min - \", minVal)\n",
"print(\"CER max - \", maxVal)\n",
"print()\n",
"\n",
"maxVal = cluster_1['OER'].max()\n",
"minVal = cluster_1['OER'].min()\n",
"\n",
"print(\"OER min - \", minVal)\n",
"print(\"OER max - \", maxVal)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e3eeb500",
"metadata": {},
"outputs": [],
"source": [
"cluster_1 = new_df[new_df[\"clusters\"] == 1 ]\n",
"display(cluster_1)\n",
"cluster_1.boxplot(column =['CER'], grid = False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10ff99a7",
"metadata": {},
"outputs": [],
"source": [
"cluster_1.boxplot(column =['OER'], grid = False)"
]
},
{
"cell_type": "markdown",
"id": "e62b9a30",
"metadata": {},
"source": [
"## Cluster 3"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "105ff3ad",
"metadata": {},
"outputs": [],
"source": [
"len(new_df[new_df[\"clusters\"] == 2])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "09b1596d",
"metadata": {},
"outputs": [],
"source": [
"cluster_2 = new_df[new_df[\"clusters\"] == 2 ]\n",
"\n",
"maxVal = cluster_2['CER'].max()\n",
"minVal = cluster_2['CER'].min()\n",
"\n",
"print(\"CER min - \", minVal)\n",
"print(\"CER max - \", maxVal)\n",
"print()\n",
"\n",
"maxVal = cluster_2['OER'].max()\n",
"minVal = cluster_2['OER'].min()\n",
"\n",
"print(\"OER min - \", minVal)\n",
"print(\"OER max - \", maxVal)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c9ac4a6",
"metadata": {},
"outputs": [],
"source": [
"cluster_2 = new_df[new_df[\"clusters\"] == 2 ]\n",
"display(cluster_2)\n",
"cluster_2.boxplot(column =['CER'], grid = False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1ee51b0b",
"metadata": {},
"outputs": [],
"source": [
"cluster_2.boxplot(column =['OER'], grid = False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c25bc1bd",
"metadata": {},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
"\n",
"# Pandas dataframe\n",
"data = pd.DataFrame({\"Cluster1\": cluster_0['CER'], \"Cluster2\": cluster_1['CER'], \"Cluster3\": cluster_2['CER']})\n",
"\n",
"# Plot the dataframe\n",
"ax = data[['Cluster1', 'Cluster2', 'Cluster3']].plot(kind='box', title='boxplot')\n",
"\n",
"# Display the plot\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c24315eb",
"metadata": {},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
"\n",
"# Pandas dataframe\n",
"data = pd.DataFrame({\"Cluster1\": cluster_0['OER'], \"Cluster2\": cluster_1['OER'], \"Cluster3\": cluster_2['OER']})\n",
"\n",
"# Plot the dataframe\n",
"ax = data[['Cluster1', 'Cluster2', 'Cluster3']].plot(kind='box', title='boxplot')\n",
"\n",
"# Display the plot\n",
"plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
This diff is collapsed.
web: uvicorn app:app --host=0.0.0.0 --port=${PORT:-5000}
\ No newline at end of file
This diff is collapsed.
from fastapi import FastAPI
import uvicorn
import pickle
from models import Performance
app=FastAPI()
model=pickle.load(open("selectivemodel.sav", "rb"))
@app.get("/{name}")
async def hello(name):
return {"Hello {} sss".format(name)}
@app.get("/")
async def greet():
return {"Hello World!"}
@app.post("/predict")
async def predict(req:Performance):
age=req.age
mrt=req.mrt
pcr=req.pcr
oer=req.oer
cer=req.cer
features=list([age,mrt,pcr,oer,cer])
predict=model.predict([features])
if(predict==1):
return {"Ans 1 {}".format(predict)}
elif (predict==2):
return {"Ans 2 {}".format(predict)}
elif (predict==3):
return {"Ans 3 {}".format(predict)}
else:
return {"Ans 4 {}".format(predict)}
if __name__=="__main__":
uvicorn.run(app, host="127.0.0.1", port=5049)
\ No newline at end of file
This diff is collapsed.
from pydantic import BaseModel
class Performance(BaseModel):
age: int
mrt: float
pcr: float
oer: float
cer: float
anyio==3.6.1
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
asttokens==2.0.8
attrs==22.1.0
backcall==0.2.0
beautifulsoup4==4.11.1
bleach==5.0.1
cffi==1.15.1
click==8.1.3
colorama==0.4.5
contourpy==1.0.5
cycler==0.11.0
debugpy==1.6.3
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
executing==1.1.0
fastapi==0.85.0
fastjsonschema==2.16.2
fonttools==4.37.4
h11==0.14.0
idna==3.4
ipykernel==6.16.0
ipython==8.5.0
ipython-genutils==0.2.0
jedi==0.18.1
Jinja2==3.1.2
joblib==1.2.0
jsonschema==4.16.0
jupyter-core==4.11.1
jupyter_client==7.3.5
jupyterlab-pygments==0.2.2
kiwisolver==1.4.4
MarkupSafe==2.1.1
matplotlib==3.6.0
matplotlib-inline==0.1.6
mistune==2.0.4
nbclient==0.6.8
nbconvert==7.1.0
nbformat==5.6.1
nest-asyncio==1.5.6
notebook==6.4.12
numpy==1.23.3
packaging==21.3
pandas==1.5.0
pandocfilters==1.5.0
parso==0.8.3
pickleshare==0.7.5
Pillow==9.2.0
playsound==1.3.0
prometheus-client==0.14.1
prompt-toolkit==3.0.31
psutil==5.9.2
pure-eval==0.2.2
pycparser==2.21
pydantic==1.10.2
Pygments==2.13.0
pyparsing==3.0.9
pyrsistent==0.18.1
python-dateutil==2.8.2
pytz==2022.4
pywin32==304;platform_system == "Windows"
pyzmq==24.0.1
scikit-learn==1.1.2
scipy==1.9.1
Send2Trash==1.8.0
six==1.16.0
sklearn==0.0
sniffio==1.3.0
soupsieve==2.3.2.post1
stack-data==0.5.1
starlette==0.20.4
terminado==0.16.0
threadpoolctl==3.1.0
tinycss2==1.1.1
tornado==6.2
traitlets==5.4.0
typing_extensions==4.3.0
uvicorn==0.18.3
wcwidth==0.2.5
webencodings==0.5.1
python-3.10.7
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment