{
"cells": [
{
"cell_type": "markdown",
"id": "423932f7-1217-4d5e-8cee-1b4e0a6855e1",
"metadata": {
"tags": []
},
"source": [
"### OCI Data Science - Useful Tips\n",
"\n",
"Check for Public Internet Access
\n",
"\n",
"```python\n",
"import requests\n",
"response = requests.get(\"https://oracle.com\")\n",
"assert response.status_code==200, \"Internet connection failed\"\n",
"```\n",
" \n",
"\n",
"Helpful Documentation
\n",
"\n",
" \n",
"\n",
"Typical Cell Imports and Settings for ADS
\n",
"\n",
"```python\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"\n",
"import logging\n",
"logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.ERROR)\n",
"\n",
"import ads\n",
"from ads.dataset.factory import DatasetFactory\n",
"from ads.automl.provider import OracleAutoMLProvider\n",
"from ads.automl.driver import AutoML\n",
"from ads.evaluations.evaluator import ADSEvaluator\n",
"from ads.common.data import ADSData\n",
"from ads.explanations.explainer import ADSExplainer\n",
"from ads.explanations.mlx_global_explainer import MLXGlobalExplainer\n",
"from ads.explanations.mlx_local_explainer import MLXLocalExplainer\n",
"from ads.catalog.model import ModelCatalog\n",
"from ads.common.model_artifact import ModelArtifact\n",
"```\n",
" \n",
"\n",
"Useful Environment Variables
\n",
"\n",
"```python\n",
"import os\n",
"print(os.environ[\"NB_SESSION_COMPARTMENT_OCID\"])\n",
"print(os.environ[\"PROJECT_OCID\"])\n",
"print(os.environ[\"USER_OCID\"])\n",
"print(os.environ[\"TENANCY_OCID\"])\n",
"print(os.environ[\"NB_REGION\"])\n",
"```\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "c8e038c6-c252-4c41-88ac-5d4d4996e59b",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "688aaeb5-6e94-4741-ab02-e6b159325a13",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"mpg = pd.read_csv('~/ns-user-38/day3/predictive_maintenance.csv')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "cc403108-5d3b-449a-b685-00fff0637761",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"(10000, 10)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mpg.shape"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "772a10b9-c4b3-4c73-b6fc-20cd5432e4cd",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" UDI | \n",
" Product ID | \n",
" Type | \n",
" Air temperature [K] | \n",
" Process temperature [K] | \n",
" Rotational speed [rpm] | \n",
" Torque [Nm] | \n",
" Tool wear [min] | \n",
" Target | \n",
" Failure Type | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 1 | \n",
" M14860 | \n",
" M | \n",
" 298.1 | \n",
" 308.6 | \n",
" 1551 | \n",
" 42.8 | \n",
" 0 | \n",
" 0 | \n",
" No Failure | \n",
"
\n",
" \n",
" | 1 | \n",
" 2 | \n",
" L47181 | \n",
" L | \n",
" 298.2 | \n",
" 308.7 | \n",
" 1408 | \n",
" 46.3 | \n",
" 3 | \n",
" 0 | \n",
" No Failure | \n",
"
\n",
" \n",
" | 2 | \n",
" 3 | \n",
" L47182 | \n",
" L | \n",
" 298.1 | \n",
" 308.5 | \n",
" 1498 | \n",
" 49.4 | \n",
" 5 | \n",
" 0 | \n",
" No Failure | \n",
"
\n",
" \n",
" | 3 | \n",
" 4 | \n",
" L47183 | \n",
" L | \n",
" 298.2 | \n",
" 308.6 | \n",
" 1433 | \n",
" 39.5 | \n",
" 7 | \n",
" 0 | \n",
" No Failure | \n",
"
\n",
" \n",
" | 4 | \n",
" 5 | \n",
" L47184 | \n",
" L | \n",
" 298.2 | \n",
" 308.7 | \n",
" 1408 | \n",
" 40.0 | \n",
" 9 | \n",
" 0 | \n",
" No Failure | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" UDI Product ID Type Air temperature [K] Process temperature [K] \\\n",
"0 1 M14860 M 298.1 308.6 \n",
"1 2 L47181 L 298.2 308.7 \n",
"2 3 L47182 L 298.1 308.5 \n",
"3 4 L47183 L 298.2 308.6 \n",
"4 5 L47184 L 298.2 308.7 \n",
"\n",
" Rotational speed [rpm] Torque [Nm] Tool wear [min] Target Failure Type \n",
"0 1551 42.8 0 0 No Failure \n",
"1 1408 46.3 3 0 No Failure \n",
"2 1498 49.4 5 0 No Failure \n",
"3 1433 39.5 7 0 No Failure \n",
"4 1408 40.0 9 0 No Failure "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mpg.head()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "e5698130-0254-46d3-94a5-05b5c32d9e6c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"mpg_update = mpg.drop(['UDI','Product ID','Type','Failure Type','Target'], axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "8473e9bf-77b0-473e-b9c2-f19996a3ec08",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Air temperature [K] | \n",
" Process temperature [K] | \n",
" Rotational speed [rpm] | \n",
" Torque [Nm] | \n",
" Tool wear [min] | \n",
"
\n",
" \n",
" \n",
" \n",
" | count | \n",
" 10000.000000 | \n",
" 10000.000000 | \n",
" 10000.000000 | \n",
" 10000.000000 | \n",
" 10000.000000 | \n",
"
\n",
" \n",
" | mean | \n",
" 300.004930 | \n",
" 310.005560 | \n",
" 1538.776100 | \n",
" 39.986910 | \n",
" 107.951000 | \n",
"
\n",
" \n",
" | std | \n",
" 2.000259 | \n",
" 1.483734 | \n",
" 179.284096 | \n",
" 9.968934 | \n",
" 63.654147 | \n",
"
\n",
" \n",
" | min | \n",
" 295.300000 | \n",
" 305.700000 | \n",
" 1168.000000 | \n",
" 3.800000 | \n",
" 0.000000 | \n",
"
\n",
" \n",
" | 25% | \n",
" 298.300000 | \n",
" 308.800000 | \n",
" 1423.000000 | \n",
" 33.200000 | \n",
" 53.000000 | \n",
"
\n",
" \n",
" | 50% | \n",
" 300.100000 | \n",
" 310.100000 | \n",
" 1503.000000 | \n",
" 40.100000 | \n",
" 108.000000 | \n",
"
\n",
" \n",
" | 75% | \n",
" 301.500000 | \n",
" 311.100000 | \n",
" 1612.000000 | \n",
" 46.800000 | \n",
" 162.000000 | \n",
"
\n",
" \n",
" | max | \n",
" 304.500000 | \n",
" 313.800000 | \n",
" 2886.000000 | \n",
" 76.600000 | \n",
" 253.000000 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Air temperature [K] Process temperature [K] Rotational speed [rpm] \\\n",
"count 10000.000000 10000.000000 10000.000000 \n",
"mean 300.004930 310.005560 1538.776100 \n",
"std 2.000259 1.483734 179.284096 \n",
"min 295.300000 305.700000 1168.000000 \n",
"25% 298.300000 308.800000 1423.000000 \n",
"50% 300.100000 310.100000 1503.000000 \n",
"75% 301.500000 311.100000 1612.000000 \n",
"max 304.500000 313.800000 2886.000000 \n",
"\n",
" Torque [Nm] Tool wear [min] \n",
"count 10000.000000 10000.000000 \n",
"mean 39.986910 107.951000 \n",
"std 9.968934 63.654147 \n",
"min 3.800000 0.000000 \n",
"25% 33.200000 53.000000 \n",
"50% 40.100000 108.000000 \n",
"75% 46.800000 162.000000 \n",
"max 76.600000 253.000000 "
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mpg_update.describe()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "82381e8b-4b7a-405e-a930-41b4875f1c35",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Product ID | \n",
" Type | \n",
" Failure Type | \n",
"
\n",
" \n",
" \n",
" \n",
" | count | \n",
" 10000 | \n",
" 10000 | \n",
" 10000 | \n",
"
\n",
" \n",
" | unique | \n",
" 10000 | \n",
" 3 | \n",
" 6 | \n",
"
\n",
" \n",
" | top | \n",
" M14860 | \n",
" L | \n",
" No Failure | \n",
"
\n",
" \n",
" | freq | \n",
" 1 | \n",
" 6000 | \n",
" 9652 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Product ID Type Failure Type\n",
"count 10000 10000 10000\n",
"unique 10000 3 6\n",
"top M14860 L No Failure\n",
"freq 1 6000 9652"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# categorcial variable summary\n",
"\n",
"mpg.describe(include=['O'])"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "c5f61e38-83be-46cb-98da-5bf56b87892d",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"RangeIndex: 10000 entries, 0 to 9999\n",
"Data columns (total 10 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 UDI 10000 non-null int64 \n",
" 1 Product ID 10000 non-null object \n",
" 2 Type 10000 non-null object \n",
" 3 Air temperature [K] 10000 non-null float64\n",
" 4 Process temperature [K] 10000 non-null float64\n",
" 5 Rotational speed [rpm] 10000 non-null int64 \n",
" 6 Torque [Nm] 10000 non-null float64\n",
" 7 Tool wear [min] 10000 non-null int64 \n",
" 8 Target 10000 non-null int64 \n",
" 9 Failure Type 10000 non-null object \n",
"dtypes: float64(3), int64(4), object(3)\n",
"memory usage: 781.4+ KB\n"
]
}
],
"source": [
"#printing data types\n",
"\n",
"mpg.info()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "91ffc9e8-814b-429f-90ef-1b20d3f34c02",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"UDI 10000\n",
"Product ID 10000\n",
"Type 3\n",
"Air temperature [K] 93\n",
"Process temperature [K] 82\n",
"Rotational speed [rpm] 941\n",
"Torque [Nm] 577\n",
"Tool wear [min] 246\n",
"Target 2\n",
"Failure Type 6\n",
"dtype: int64"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mpg.nunique()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "de56763d-31cc-45d9-887c-d2a0f76956f5",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"UDI 0\n",
"Product ID 0\n",
"Type 0\n",
"Air temperature [K] 0\n",
"Process temperature [K] 0\n",
"Rotational speed [rpm] 0\n",
"Torque [Nm] 0\n",
"Tool wear [min] 0\n",
"Target 0\n",
"Failure Type 0\n",
"dtype: int64"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#check for missing entries\n",
"mpg.isnull().sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8a15fe03-d630-4108-ba07-97ba6b1ba4f6",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:ns-user-38_v1]",
"language": "python",
"name": "conda-env-ns-user-38_v1-py"
},
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}