Skip to content

Commit

Permalink
Final touches 💯
Browse files Browse the repository at this point in the history
  • Loading branch information
Dheeraj1998 committed Apr 30, 2019
1 parent dae0239 commit 8534028
Show file tree
Hide file tree
Showing 41 changed files with 519 additions and 1,083 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Notebook for offline trained ML model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Importing the required libraries"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import csv\n",
"import scipy.signal\n",
"import serial\n",
"import numpy as np\n",
"import urllib.request \n",
"\n",
"import scipy.signal\n",
"from sklearn.externals import joblib"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Loading the serial port"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -28,6 +49,13 @@
" print(\"Please check the port.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Acquisition of the data and parameter extraction"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -65,34 +93,25 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[490.0, 496.0, 6.0, 496.0, 496.0, 496.0, 495.22]\n"
]
}
],
"outputs": [],
"source": [
"print('\\nThe parameters of this signal are: ', extracted_parameters)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Viewing the confidence values of the data"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'ceramics': 0.0390936227134829, 'plastic': 0.9253597476988202, 'wood': 0.03554662958769686}\n"
]
}
],
"outputs": [],
"source": [
"inputarray = extracted_parameters[:7]\n",
"clf = joblib.load('model.pkl')\n",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,141 @@
{
"cells": [],
"metadata": {},
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Notebook for Heroku hosted ML API"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Importing libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import csv\n",
"import scipy.signal\n",
"import serial\n",
"import numpy as np\n",
"import urllib.request "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Loading the serial port"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" arduino = serial.Serial(\"/COM9\",timeout=1)\n",
" print(\"The port has been successfully loaded.\")\n",
"except:\n",
" print(\"Please check the port.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Acquiring the data and extracting the parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataset = []\n",
"data_count = 0\n",
"\n",
"while data_count<11:\n",
" rawdata = []\n",
" count = 0\n",
" while count<100:\n",
" rawdata.append(int(arduino.readline()))\n",
" count+=1\n",
" dataset.append(rawdata)\n",
" data_count+=1\n",
"\n",
"# Filtering of the input values\n",
"filtered_values = []\n",
"\n",
"mean_value = np.mean(dataset[10])\n",
"value_25 = np.percentile(dataset[10], 25)\n",
"value_75 = np.percentile(dataset[10], 75)\n",
"\n",
"for value in dataset[0]:\n",
" filtered_values.append(value_75 if value > mean_value else value_25)\n",
" \n",
"url_parameter = \"\"\n",
"for i in range(0,len(filtered_values)):\n",
" if(i<len(filtered_values)-1):\n",
" url_parameter += str(filtered_values[i])\n",
" url_parameter += \",\"\n",
" else:\n",
" url_parameter += str(filtered_values[i])\n",
"\n",
"# Extraction of the signal parameters\n",
"extracted_parameters = [np.amin(filtered_values), np.amax(filtered_values),\n",
" np.ptp(filtered_values), np.percentile(filtered_values, 75),\n",
" np.percentile(filtered_values, 25), np.median(filtered_values),\n",
" np.mean(filtered_values), round(np.std(filtered_values),2),\n",
" round(np.var(filtered_values),2), round(scipy.stats.kurtosis(filtered_values),2),\n",
" round(scipy.stats.skew(filtered_values),2)]\n",
"\n",
"print('\\nThe parameters of this signal are: ', extracted_parameters)\n",
"\n",
"# Calling the web API\n",
"web_api_url = \"https://pacific-harbor-19774.herokuapp.com/predict?myvar=\" + str(url_parameter)\n",
"print('\\nThe web API URL is: ', web_api_url)\n",
"\n",
"urllib.request.urlopen(web_api_url)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"arduino.close()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

This file was deleted.

This file was deleted.

281 changes: 146 additions & 135 deletions Data_Analysis_Python/Data Classification.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 8534028

Please sign in to comment.