From 3515e58c2bd97567d77f9b1661df4e9faab1bca9 Mon Sep 17 00:00:00 2001
From: Wajdi <62748386+wajdi404@users.noreply.github.com>
Date: Mon, 30 Sep 2024 15:11:19 +0100
Subject: [PATCH] Created using Colab
---
TinyML.ipynb | 1552 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 1552 insertions(+)
create mode 100644 TinyML.ipynb
diff --git a/TinyML.ipynb b/TinyML.ipynb
new file mode 100644
index 0000000..a982421
--- /dev/null
+++ b/TinyML.ipynb
@@ -0,0 +1,1552 @@
+{
+ "nbformat": 4,
+ "nbformat_minor": 0,
+ "metadata": {
+ "colab": {
+ "provenance": [],
+ "include_colab_link": true
+ },
+ "kernelspec": {
+ "name": "python3",
+ "display_name": "Python 3"
+ },
+ "language_info": {
+ "name": "python"
+ }
+ },
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "view-in-github",
+ "colab_type": "text"
+ },
+ "source": [
+ ""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "import requests\n",
+ "import zipfile\n",
+ "import os\n",
+ "\n",
+ "# URL of the dataset\n",
+ "url = 'https://zenodo.org/records/4686379/files/iotj_dataset_zenodo.zip?download=1'\n",
+ "\n",
+ "# Define the local filename to save the dataset\n",
+ "local_filename = 'iotj_dataset_zenodo.zip'\n",
+ "\n",
+ "# Download the file from the URL\n",
+ "response = requests.get(url, stream=True)\n",
+ "\n",
+ "# Save the file locally\n",
+ "with open(local_filename, 'wb') as file:\n",
+ " for chunk in response.iter_content(chunk_size=128):\n",
+ " file.write(chunk)\n",
+ "\n",
+ "print(f\"Dataset downloaded and saved as {local_filename}\")"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "qoAsvUYWAJcF",
+ "outputId": "eafa67f1-50e7-46d1-d046-ed78780a1904"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Dataset downloaded and saved as iotj_dataset_zenodo.zip\n",
+ "Dataset extracted to 'iotj_dataset' folder\n"
+ ]
+ },
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "['iotj_dataset_zenodo']"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 6
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "local_filename = '.zip'\n",
+ "# Unzip the downloaded file\n",
+ "with zipfile.ZipFile(local_filename, 'r') as zip_ref:\n",
+ " zip_ref.extractall(\"iotj_dataset\")\n",
+ " print(\"Dataset extracted to 'iotj_dataset' folder\")"
+ ],
+ "metadata": {
+ "id": "VPk70X2HAqdG"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# Check the contents of the folder\n",
+ "os.listdir(\"/content/iotj_dataset/iotj_dataset_zenodo\")"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "roB6oNFBAoTI",
+ "outputId": "e90c9613-8165-4d95-c00f-b6621bb976af"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "['photos', 'localization', 'ranging', 'readme.md']"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 10
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "def print_directory_tree(root_dir, indent=\"\"):\n",
+ " # Print the current directory\n",
+ " print(f\"{indent}|-- {os.path.basename(root_dir)}/\")\n",
+ "\n",
+ " # Get the list of directories in the current directory\n",
+ " items = os.listdir(root_dir)\n",
+ " dirs = [item for item in items if os.path.isdir(os.path.join(root_dir, item))]\n",
+ "\n",
+ " # Recursively print the directories\n",
+ " for d in dirs:\n",
+ " print_directory_tree(os.path.join(root_dir, d), indent + \" \")\n",
+ "\n",
+ "\n",
+ "# Print the directory structure for the \"iotj_dataset\"\n",
+ "print_directory_tree(\"/content/iotj_dataset/iotj_dataset_zenodo/ranging\")"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "mpQjKUEeBt3D",
+ "outputId": "294f80b2-e19d-4202-8054-4ed90b016844"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "|-- ranging/\n",
+ " |-- code/\n",
+ " |-- data/\n",
+ " |-- 3db/\n",
+ " |-- 3db_rec_16/\n",
+ " |-- 3db_rec_3/\n",
+ " |-- backup/\n",
+ " |-- 3db_rec_11/\n",
+ " |-- 3db_rec_1/\n",
+ " |-- 3db_rec_6/\n",
+ " |-- 3db_rec_9/\n",
+ " |-- 3db_rec_4/\n",
+ " |-- 3db_rec_13/\n",
+ " |-- 3db_rec_12/\n",
+ " |-- 3db_rec_17/\n",
+ " |-- 3db_rec_10/\n",
+ " |-- 3db_rec_15/\n",
+ " |-- 3db_rec_7/\n",
+ " |-- 3db_rec_5/\n",
+ " |-- backup/\n",
+ " |-- 3db_rec_16/\n",
+ " |-- 3db_rec_3/\n",
+ " |-- backup/\n",
+ " |-- 3db_rec_11/\n",
+ " |-- 3db_rec_1/\n",
+ " |-- 3db_rec_6/\n",
+ " |-- 3db_rec_19/\n",
+ " |-- 3db_rec_9/\n",
+ " |-- 3db_rec_4/\n",
+ " |-- 3db_rec_13/\n",
+ " |-- 3db_rec_12/\n",
+ " |-- 3db_rec_17/\n",
+ " |-- 3db_rec_10/\n",
+ " |-- 3db_rec_15/\n",
+ " |-- 3db_rec_7/\n",
+ " |-- 3db_rec_5/\n",
+ " |-- 3db_rec_18/\n",
+ " |-- 3db_rec_2/\n",
+ " |-- 3db_rec_14/\n",
+ " |-- 3db_rec_8/\n",
+ " |-- 3db_rec_18/\n",
+ " |-- 3db_rec_2/\n",
+ " |-- 3db_rec_14/\n",
+ " |-- 3db_rec_8/\n",
+ " |-- decawave/\n",
+ " |-- dw_rec_3/\n",
+ " |-- dw_rec_4/\n",
+ " |-- dw_rec_1/\n",
+ " |-- dw_rec_2/\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "import matplotlib.pyplot as plt\n",
+ "\n",
+ "# Load the CSV files\n",
+ "\n",
+ "\n",
+ "dw_rec_1_pd = pd.read_csv( \"/content/iotj_dataset/iotj_dataset_zenodo/ranging/data/decawave/dw_rec_1/data.csv\")\n",
+ "dw_rec_2_pd = pd.read_csv( \"/content/iotj_dataset/iotj_dataset_zenodo/ranging/data/decawave/dw_rec_2/data.csv\")\n",
+ "dw_rec_3_pd = pd.read_csv( \"/content/iotj_dataset/iotj_dataset_zenodo/ranging/data/decawave/dw_rec_3/data.csv\")\n",
+ "dw_rec_4_pd = pd.read_csv( \"/content/iotj_dataset/iotj_dataset_zenodo/ranging/data/decawave/dw_rec_4/data.csv\")\n",
+ "\n",
+ "# Extract 'true_dist' and 'measured_dist' columns from each DataFrame\n",
+ "dw_rec_1_subset = dw_rec_1_pd[['true_dist', 'measured_dist']]\n",
+ "dw_rec_2_subset = dw_rec_2_pd[['true_dist', 'measured_dist']]\n",
+ "dw_rec_3_subset = dw_rec_3_pd[['true_dist', 'measured_dist']]\n",
+ "dw_rec_4_subset = dw_rec_4_pd[['true_dist', 'measured_dist']]\n",
+ "\n",
+ "# Concatenate the extracted columns from all four files into one DataFrame\n",
+ "combined_df = pd.concat([dw_rec_1_subset, dw_rec_2_subset, dw_rec_3_subset, dw_rec_4_subset], ignore_index=True)"
+ ],
+ "metadata": {
+ "id": "LYXYa7GIDLVY"
+ },
+ "execution_count": 27,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "combined_df"
+ ],
+ "metadata": {
+ "id": "P6dkHksUK1lO",
+ "outputId": "9addd0f8-253e-4d58-98d7-00e82f0bb822",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 424
+ }
+ },
+ "execution_count": 28,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " true_dist measured_dist\n",
+ "0 1 0.953603\n",
+ "1 1 1.004472\n",
+ "2 1 0.943430\n",
+ "3 1 0.943430\n",
+ "4 1 0.963777\n",
+ "... ... ...\n",
+ "5195 3 3.491634\n",
+ "5196 3 3.441934\n",
+ "5197 3 3.511514\n",
+ "5198 3 3.451874\n",
+ "5199 3 3.451874\n",
+ "\n",
+ "[5200 rows x 2 columns]"
+ ],
+ "text/html": [
+ "\n",
+ "
| \n", + " | true_dist | \n", + "measured_dist | \n", + "
|---|---|---|
| 0 | \n", + "1 | \n", + "0.953603 | \n", + "
| 1 | \n", + "1 | \n", + "1.004472 | \n", + "
| 2 | \n", + "1 | \n", + "0.943430 | \n", + "
| 3 | \n", + "1 | \n", + "0.943430 | \n", + "
| 4 | \n", + "1 | \n", + "0.963777 | \n", + "
| ... | \n", + "... | \n", + "... | \n", + "
| 5195 | \n", + "3 | \n", + "3.491634 | \n", + "
| 5196 | \n", + "3 | \n", + "3.441934 | \n", + "
| 5197 | \n", + "3 | \n", + "3.511514 | \n", + "
| 5198 | \n", + "3 | \n", + "3.451874 | \n", + "
| 5199 | \n", + "3 | \n", + "3.451874 | \n", + "
5200 rows × 2 columns
\n", + "| \n", + " | true_dist | \n", + "measured_dist | \n", + "
|---|---|---|
| 0 | \n", + "3 | \n", + "2.964814 | \n", + "
| 1 | \n", + "2 | \n", + "1.909937 | \n", + "
| 2 | \n", + "3 | \n", + "2.964814 | \n", + "
| 3 | \n", + "2 | \n", + "2.357582 | \n", + "
| 4 | \n", + "5 | \n", + "4.773893 | \n", + "
| ... | \n", + "... | \n", + "... | \n", + "
| 5195 | \n", + "5 | \n", + "5.948919 | \n", + "
| 5196 | \n", + "2 | \n", + "2.318715 | \n", + "
| 5197 | \n", + "2 | \n", + "2.378355 | \n", + "
| 5198 | \n", + "2 | \n", + "2.030455 | \n", + "
| 5199 | \n", + "5 | \n", + "4.803713 | \n", + "
5200 rows × 2 columns
\n", + "RandomForestRegressor(random_state=42)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
RandomForestRegressor(random_state=42)