{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "NItwWaXSWOqs" }, "source": [ "# Практическая работа #3\n", "\n", "# Визуализация многомерных данных. Создание пиктограмм при помощи Matplotlib.\n" ] }, { "cell_type": "markdown", "metadata": { "id": "8gbb-O0w85SM" }, "source": [ "Для выполнения данной практической работы предлагается проанализировать набор данных Data of rotary machine defects , который доступен для скачивания на Kaggle.\n", "Этот набор данных представляет собой результаты эксперимента по выявлению дефектов в подшипниковых узлах жидкостного трения. Время эксперимента 10 мин. Частота получения данных о колебаниях ротора 1000 сиг/сек. Частота съема данных о температуре 1 сиг/сек. \n", "Первая цифра в названии файла указывает на номер эксперимента, а вторая на класс дефекта. Соответствие номера дефекта и его вида: \n", "‒\t1 - нет дефектов, \n", "‒\t2 - несоосность в муфте, \n", "‒\t3 - наличие дисбаланса, \n", "‒\t4 - втулка с дефектами.\n", "\n", "Каждый столбец соответствует определенному параметру, в строках распо-ложены значения показаний с датчиков в каждый временной промежуток време-ни. Данные датчиков температуры продублированы для каждой секунды, для упрощения соотношения данных. " ] }, { "cell_type": "markdown", "metadata": { "id": "00OjFiLhjU3e" }, "source": [ "## Init" ] }, { "cell_type": "code", "source": [ "Зависит от используемой Вами среды." ], "metadata": { "id": "NXoWtlkK_jLg" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "-gxqkCpy85SN", "outputId": "5cb6a2ea-c3f7-41d3-bfe8-45b8b7bc9aaa" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.8/dist-packages (1.21.6)\n", "Requirement already satisfied: scipy in /usr/local/lib/python3.8/dist-packages (1.7.3)\n", "Requirement already satisfied: scikit-learn in /usr/local/lib/python3.8/dist-packages (1.0.2)\n", "Collecting jupyter\n", " Downloading jupyter-1.0.0-py2.py3-none-any.whl (2.7 kB)\n", "Requirement already satisfied: matplotlib in /usr/local/lib/python3.8/dist-packages (3.2.2)\n", "Requirement already satisfied: pandas in /usr/local/lib/python3.8/dist-packages (1.3.5)\n", "Requirement already satisfied: seaborn in /usr/local/lib/python3.8/dist-packages (0.11.2)\n", "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.8/dist-packages (from scikit-learn) (3.1.0)\n", "Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.8/dist-packages (from scikit-learn) (1.2.0)\n", "Requirement already satisfied: notebook in /usr/local/lib/python3.8/dist-packages (from jupyter) (5.7.16)\n", "Collecting qtconsole\n", " Downloading qtconsole-5.4.0-py3-none-any.whl (121 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m121.0/121.0 KB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: jupyter-console in /usr/local/lib/python3.8/dist-packages (from jupyter) (6.1.0)\n", "Requirement already satisfied: nbconvert in /usr/local/lib/python3.8/dist-packages (from jupyter) (5.6.1)\n", "Requirement already satisfied: ipywidgets in /usr/local/lib/python3.8/dist-packages (from jupyter) (7.7.1)\n", "Requirement already satisfied: ipykernel in /usr/local/lib/python3.8/dist-packages (from jupyter) (5.3.4)\n", "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.8/dist-packages (from matplotlib) (0.11.0)\n", "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib) (3.0.9)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib) (1.4.4)\n", "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib) (2.8.2)\n", "Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.8/dist-packages (from pandas) (2022.7.1)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.8/dist-packages (from python-dateutil>=2.1->matplotlib) (1.15.0)\n", "Requirement already satisfied: ipython>=5.0.0 in /usr/local/lib/python3.8/dist-packages (from ipykernel->jupyter) (7.9.0)\n", "Requirement already satisfied: jupyter-client in /usr/local/lib/python3.8/dist-packages (from ipykernel->jupyter) (6.1.12)\n", "Requirement already satisfied: traitlets>=4.1.0 in /usr/local/lib/python3.8/dist-packages (from ipykernel->jupyter) (5.7.1)\n", "Requirement already satisfied: tornado>=4.2 in /usr/local/lib/python3.8/dist-packages (from ipykernel->jupyter) (6.0.4)\n", "Requirement already satisfied: ipython-genutils~=0.2.0 in /usr/local/lib/python3.8/dist-packages (from ipywidgets->jupyter) (0.2.0)\n", "Requirement already satisfied: widgetsnbextension~=3.6.0 in /usr/local/lib/python3.8/dist-packages (from ipywidgets->jupyter) (3.6.1)\n", "Requirement already satisfied: jupyterlab-widgets>=1.0.0 in /usr/local/lib/python3.8/dist-packages (from ipywidgets->jupyter) (3.0.5)\n", "Requirement already satisfied: pygments in /usr/local/lib/python3.8/dist-packages (from jupyter-console->jupyter) (2.6.1)\n", "Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /usr/local/lib/python3.8/dist-packages (from jupyter-console->jupyter) (2.0.10)\n", "Requirement already satisfied: jupyter-core in /usr/local/lib/python3.8/dist-packages (from nbconvert->jupyter) (5.2.0)\n", "Requirement already satisfied: testpath in /usr/local/lib/python3.8/dist-packages (from nbconvert->jupyter) (0.6.0)\n", "Requirement already satisfied: pandocfilters>=1.4.1 in /usr/local/lib/python3.8/dist-packages (from nbconvert->jupyter) (1.5.0)\n", "Requirement already satisfied: defusedxml in /usr/local/lib/python3.8/dist-packages (from nbconvert->jupyter) (0.7.1)\n", "Requirement already satisfied: jinja2>=2.4 in /usr/local/lib/python3.8/dist-packages (from nbconvert->jupyter) (2.11.3)\n", "Requirement already satisfied: nbformat>=4.4 in /usr/local/lib/python3.8/dist-packages (from nbconvert->jupyter) (5.7.3)\n", "Requirement already satisfied: entrypoints>=0.2.2 in /usr/local/lib/python3.8/dist-packages (from nbconvert->jupyter) (0.4)\n", "Requirement already satisfied: bleach in /usr/local/lib/python3.8/dist-packages (from nbconvert->jupyter) (6.0.0)\n", "Requirement already satisfied: mistune<2,>=0.8.1 in /usr/local/lib/python3.8/dist-packages (from nbconvert->jupyter) (0.8.4)\n", "Requirement already satisfied: terminado>=0.8.1 in /usr/local/lib/python3.8/dist-packages (from notebook->jupyter) (0.13.3)\n", "Requirement already satisfied: Send2Trash in /usr/local/lib/python3.8/dist-packages (from notebook->jupyter) (1.8.0)\n", "Requirement already satisfied: prometheus-client in /usr/local/lib/python3.8/dist-packages (from notebook->jupyter) (0.16.0)\n", "Requirement already satisfied: pyzmq>=17 in /usr/local/lib/python3.8/dist-packages (from notebook->jupyter) (23.2.1)\n", "Collecting qtpy>=2.0.1\n", " Downloading QtPy-2.3.0-py3-none-any.whl (83 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m83.6/83.6 KB\u001b[0m \u001b[31m5.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: pexpect in /usr/local/lib/python3.8/dist-packages (from ipython>=5.0.0->ipykernel->jupyter) (4.8.0)\n", "Requirement already satisfied: pickleshare in /usr/local/lib/python3.8/dist-packages (from ipython>=5.0.0->ipykernel->jupyter) (0.7.5)\n", "Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.8/dist-packages (from ipython>=5.0.0->ipykernel->jupyter) (57.4.0)\n", "Collecting jedi>=0.10\n", " Downloading jedi-0.18.2-py2.py3-none-any.whl (1.6 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.6/1.6 MB\u001b[0m \u001b[31m25.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: decorator in /usr/local/lib/python3.8/dist-packages (from ipython>=5.0.0->ipykernel->jupyter) (4.4.2)\n", "Requirement already satisfied: backcall in /usr/local/lib/python3.8/dist-packages (from ipython>=5.0.0->ipykernel->jupyter) (0.2.0)\n", "Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.8/dist-packages (from jinja2>=2.4->nbconvert->jupyter) (2.0.1)\n", "Requirement already satisfied: platformdirs>=2.5 in /usr/local/lib/python3.8/dist-packages (from jupyter-core->nbconvert->jupyter) (3.0.0)\n", "Requirement already satisfied: fastjsonschema in /usr/local/lib/python3.8/dist-packages (from nbformat>=4.4->nbconvert->jupyter) (2.16.2)\n", "Requirement already satisfied: jsonschema>=2.6 in /usr/local/lib/python3.8/dist-packages (from nbformat>=4.4->nbconvert->jupyter) (4.3.3)\n", "Requirement already satisfied: wcwidth in /usr/local/lib/python3.8/dist-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->jupyter-console->jupyter) (0.2.6)\n", "Requirement already satisfied: packaging in /usr/local/lib/python3.8/dist-packages (from qtpy>=2.0.1->qtconsole->jupyter) (23.0)\n", "Requirement already satisfied: ptyprocess in /usr/local/lib/python3.8/dist-packages (from terminado>=0.8.1->notebook->jupyter) (0.7.0)\n", "Requirement already satisfied: webencodings in /usr/local/lib/python3.8/dist-packages (from bleach->nbconvert->jupyter) (0.5.1)\n", "Requirement already satisfied: parso<0.9.0,>=0.8.0 in /usr/local/lib/python3.8/dist-packages (from jedi>=0.10->ipython>=5.0.0->ipykernel->jupyter) (0.8.3)\n", "Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /usr/local/lib/python3.8/dist-packages (from jsonschema>=2.6->nbformat>=4.4->nbconvert->jupyter) (0.19.3)\n", "Requirement already satisfied: importlib-resources>=1.4.0 in /usr/local/lib/python3.8/dist-packages (from jsonschema>=2.6->nbformat>=4.4->nbconvert->jupyter) (5.10.2)\n", "Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.8/dist-packages (from jsonschema>=2.6->nbformat>=4.4->nbconvert->jupyter) (22.2.0)\n", "Requirement already satisfied: zipp>=3.1.0 in /usr/local/lib/python3.8/dist-packages (from importlib-resources>=1.4.0->jsonschema>=2.6->nbformat>=4.4->nbconvert->jupyter) (3.12.1)\n", "Installing collected packages: qtpy, jedi, qtconsole, jupyter\n", "Successfully installed jedi-0.18.2 jupyter-1.0.0 qtconsole-5.4.0 qtpy-2.3.0\n" ] } ], "source": [ "# Install a pip package in the current Jupyter kernel\n", "import sys\n", "\n", "!{sys.executable} -m pip install numpy scipy scikit-learn jupyter matplotlib pandas seaborn\n", "%matplotlib inline\n", "\n", "import zipfile\n", "import os\n", "\n", "import numpy as np\n", "import seaborn as sns\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "\n", "from sklearn import preprocessing\n", "from IPython.display import Image\n", "from matplotlib.patches import Ellipse, PathPatch, Arc, Polygon, Wedge\n", "\n", "plt.rcParams['figure.dpi'] = 300" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "MZqU-x8ZO_Em" }, "outputs": [], "source": [ "# https://www.kaggle.com/datasets/kazakovyurii/data-of-rotary-machine-defects\n", "dataset_path = \"dataset\"\n", "zip_path = \"archive.zip\"\n", "\n", "# if not os.path.exists(dataset_path):\n", "# os.mkdir(dataset_path)\n", " \n", "# with zipfile.ZipFile(zip_path, \"r\") as zip_ref:\n", "# zip_ref.extractall(\"dataset\")" ] }, { "cell_type": "markdown", "metadata": { "id": "6aMHxrFtnC5N" }, "source": [ "## Загрузка данных" ] }, { "cell_type": "markdown", "metadata": { "id": "KrWLbjLwdyIr" }, "source": [ "### About data\n", "\n", "| **Field** | **Units** | **Description** |\n", "|---|---|---|\n", "| **Fluctuations_X_in_the_left_bearing** | [V] | Horizontal horizons in the left bearing, in Volts |\n", "| **Fluctuations_Y_in_the_left_bearing** | [V] | Vertical oscillations in the left bearing, in Volts |\n", "| **Fluctuations_X_in_the_right_bearing** | [V] | Horizontal vibrations in the right bearing, in Volts |\n", "| **Fluctuations_Y_in_the_right_bearing** | [V] | Vertical vibrations in the right bearing bearing, in Volts |\n", "| **Fluctuations_X_in_the_left_bearing_smooth** | [V] | Horizontal vibrations in the left bearing, taking into account smoothing, in Volts |\n", "| **Fluctuations_Y_in_the_left_bearing_smooth** | [V] | Vertical vibrations in the left bearing, taking into account smoothing, in Volts |\n", "| **Fluctuations_X_in_the_right_bearing_smooth** | [V] | Horizontal vibrations in the right bearing, taking into account smoothing, in Volts |\n", "| **Fluctuations_Y_in_the_right_bearing_smooth** | [V] | Vertical vibrations in the right bearing bearing, taking into account smoothing, in Volts |\n", "| **Temperature_in_the_left_bearing** | [V] | Temperature in the left bearing, in ohms |\n", "| **Temperature_in_the_right_bearing** | [O] | Temperature in the right bearing, in ohms |\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "lbCs2UmmpAdt" }, "source": [ "### Извлечение данных" ] }, { "cell_type": "markdown", "source": [ "Зависит от среды разработки. Проверьте корректность путей для загрузки данных.\n", "\n" ], "metadata": { "id": "OE3UUrxDAXID" } }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "uKfPItkAZRVi" }, "outputs": [], "source": [ "data = [pd.read_csv(f\"/content/data_2_{i}.csv\") for i in range(1, 5)]\n", "data = [d.rename(columns=lambda x: x.strip()) for d in data]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "jXCmeqY6ZwXD" }, "outputs": [], "source": [ "tracked_columns =[\n", " \"Fluctuations_X_in_the_left_bearing\",\n", " \"Fluctuations_Y_in_the_left_bearing\",\n", " \"Fluctuations_X_in_the_right_bearing\",\n", " \"Fluctuations_Y_in_the_right_bearing\",\n", " \"Fluctuations_X_in_the_left_bearing_smooth\",\n", " \"Fluctuations_Y_in_the_left_bearing_smooth\",\n", " \"Fluctuations_X_in_the_right_bearing_smooth\",\n", " \"Fluctuations_Y_in_the_right_bearing_smooth\",\n", " \"Temperature_in_the_left_bearing\",\n", " \"Temperature_in_the_right_bearing\"\n", "]\n", "\n", "data = [d[tracked_columns] for d in data]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 270 }, "id": "Q9hmNZN3dBAT", "outputId": "78e4082c-2e21-452b-8644-9b12fe03fc20" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " Fluctuations_X_in_the_left_bearing Fluctuations_Y_in_the_left_bearing \\\n", "0 5.671 6.404 \n", "1 5.599 6.298 \n", "2 5.589 6.236 \n", "3 5.489 6.414 \n", "4 5.623 6.455 \n", "\n", " Fluctuations_X_in_the_right_bearing Fluctuations_Y_in_the_right_bearing \\\n", "0 6.040 7.257 \n", "1 5.758 7.203 \n", "2 5.654 7.165 \n", "3 5.632 7.319 \n", "4 5.791 7.310 \n", "\n", " Fluctuations_X_in_the_left_bearing_smooth \\\n", "0 5.442 \n", "1 5.641 \n", "2 5.571 \n", "3 5.471 \n", "4 5.592 \n", "\n", " Fluctuations_Y_in_the_left_bearing_smooth \\\n", "0 6.486 \n", "1 6.361 \n", "2 6.249 \n", "3 6.294 \n", "4 6.440 \n", "\n", " Fluctuations_X_in_the_right_bearing_smooth \\\n", "0 5.593 \n", "1 5.838 \n", "2 5.700 \n", "3 5.645 \n", "4 5.716 \n", "\n", " Fluctuations_Y_in_the_right_bearing_smooth \\\n", "0 7.145 \n", "1 7.206 \n", "2 7.192 \n", "3 7.219 \n", "4 7.349 \n", "\n", " Temperature_in_the_left_bearing Temperature_in_the_right_bearing \n", "0 1104.633 1104.664 \n", "1 1104.633 1104.664 \n", "2 1104.633 1104.664 \n", "3 1104.633 1104.664 \n", "4 1104.633 1104.664 " ], "text/html": [ "\n", "
\n", " | Fluctuations_X_in_the_left_bearing | \n", "Fluctuations_Y_in_the_left_bearing | \n", "Fluctuations_X_in_the_right_bearing | \n", "Fluctuations_Y_in_the_right_bearing | \n", "Fluctuations_X_in_the_left_bearing_smooth | \n", "Fluctuations_Y_in_the_left_bearing_smooth | \n", "Fluctuations_X_in_the_right_bearing_smooth | \n", "Fluctuations_Y_in_the_right_bearing_smooth | \n", "Temperature_in_the_left_bearing | \n", "Temperature_in_the_right_bearing | \n", "
---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "5.671 | \n", "6.404 | \n", "6.040 | \n", "7.257 | \n", "5.442 | \n", "6.486 | \n", "5.593 | \n", "7.145 | \n", "1104.633 | \n", "1104.664 | \n", "
1 | \n", "5.599 | \n", "6.298 | \n", "5.758 | \n", "7.203 | \n", "5.641 | \n", "6.361 | \n", "5.838 | \n", "7.206 | \n", "1104.633 | \n", "1104.664 | \n", "
2 | \n", "5.589 | \n", "6.236 | \n", "5.654 | \n", "7.165 | \n", "5.571 | \n", "6.249 | \n", "5.700 | \n", "7.192 | \n", "1104.633 | \n", "1104.664 | \n", "
3 | \n", "5.489 | \n", "6.414 | \n", "5.632 | \n", "7.319 | \n", "5.471 | \n", "6.294 | \n", "5.645 | \n", "7.219 | \n", "1104.633 | \n", "1104.664 | \n", "
4 | \n", "5.623 | \n", "6.455 | \n", "5.791 | \n", "7.310 | \n", "5.592 | \n", "6.440 | \n", "5.716 | \n", "7.349 | \n", "1104.633 | \n", "1104.664 | \n", "