{ "cells": [ { "cell_type": "markdown", "id": "6a039863", "metadata": {}, "source": [ "# Assisted Machine learning analysis" ] }, { "cell_type": "markdown", "id": "9461ab95", "metadata": {}, "source": [ "The goal of this notebook is to create models to understand the influence of static variables on a dynamic variable. In this example we are going to predict the UER, but any other dynamic variable can be predicted.\n", "\n", "If you want more explanations, you can find in the documentation a part dedicated to explain the different concepts." ] }, { "cell_type": "markdown", "id": "da9c824f", "metadata": { "lines_to_next_cell": 2 }, "source": [ "## Import" ] }, { "cell_type": "code", "execution_count": 1, "id": "260b191e", "metadata": { "execution": { "iopub.execute_input": "2026-11-25T13:59:42.262155Z", "iopub.status.busy": "2026-11-25T13:59:42.261858Z", "iopub.status.idle": "2026-11-25T13:59:44.231674Z", "shell.execute_reply": "2026-11-25T13:59:44.230874Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/env/lib/python3.8/site-packages/category_encoders/target_encoder.py:92: FutureWarning: Default parameter min_samples_leaf will change in version 2.6.See https://github.com/scikit-learn-contrib/category_encoders/issues/327\n", " warnings.warn(\"Default parameter min_samples_leaf will change in version 2.6.\"\n", "/env/lib/python3.8/site-packages/category_encoders/target_encoder.py:97: FutureWarning: Default parameter smoothing will change in version 2.6.See https://github.com/scikit-learn-contrib/category_encoders/issues/327\n", " warnings.warn(\"Default parameter smoothing will change in version 2.6.\"\n" ] } ], "source": [ "import frflib\n", "import sklearn\n", "from frflib.utils.ml_analysis.optimizer import MLDataset\n", "\n", "from frflib.utils.ml_analysis.processing import (\n", " make_static_list,\n", " make_pipeline,\n", " make_dict_preprocessing,\n", " ONE_HOT_ENCODER,\n", " TARGET_ENCODER,\n", " REGROUP_ENCODER,\n", " XYSCALER,\n", " MINMAX,\n", " STANDARD_SCALER,\n", " UNCHANGED,\n", ")\n", "from frflib.utils.ml_analysis.analysis import (\n", " find_best_model_param,\n", " model_analysis,\n", " fit_model,\n", " build_model_summary,\n", ")\n", "from frflib.utils.ml_analysis.simulation import (\n", " get_truncated_normal,\n", " get_percentile,\n", " discretize,\n", " check_enough_data,\n", " generate_df_simulation,\n", ")\n", "from sklearn.model_selection import train_test_split\n", "\n", "from frflib.data_class.input_data import InputData\n", "from frflib.forecast_methods import forecast_wf\n", "from frflib.plots.plotly_ import plot_scatter\n", "import plotly.express as px\n", "\n", "\n", "ForecastWF = forecast_wf.ForecastWF\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import numpy as np\n", "import plotly.figure_factory as ff\n", "import plotly.express as px\n", "import os\n", "import inspect\n", "from sklearn.metrics import r2_score, mean_absolute_error, mean_squared_error" ] }, { "cell_type": "markdown", "id": "0df6711f", "metadata": {}, "source": [ "## Load data" ] }, { "cell_type": "code", "execution_count": 2, "id": "b85bf669", "metadata": { "execution": { "iopub.execute_input": "2026-11-25T13:59:44.234533Z", "iopub.status.busy": "2026-11-25T13:59:44.234285Z", "iopub.status.idle": "2026-11-25T13:59:44.238643Z", "shell.execute_reply": "2026-11-25T13:59:44.237874Z" } }, "outputs": [], "source": [ "PATH_FRFLIB = os.path.dirname(inspect.getsourcefile(frflib))\n", "PATH_TO_DATA = os.path.join(PATH_FRFLIB, \"sample_data\")\n", "\n", "project_id = \"01\"\n", "wf_name = \"dataset_01_simple_wf\"\n", "\n", "WF_PATH = os.path.join(PATH_TO_DATA, f\"{wf_name}.hdf\")\n", "DATA_PATH = os.path.join(PATH_TO_DATA, f\"dataset_{project_id}.hdf\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "2219ff81", "metadata": { "execution": { "iopub.execute_input": "2026-11-25T13:59:44.240947Z", "iopub.status.busy": "2026-11-25T13:59:44.240722Z", "iopub.status.idle": "2026-11-25T13:59:46.035619Z", "shell.execute_reply": "2026-11-25T13:59:46.034905Z" } }, "outputs": [ { "data": { "text/html": [ "
| \n", " | production_name | \n", "wellbore | \n", "reservoir | \n", "sub_group | \n", "ptr_main_layer_total | \n", "ptr_main _layer | \n", "ptr_secondary_layer | \n", "cluster | \n", "avg_poro_vv | \n", "avg_vcl_vv | \n", "... | \n", "z_bh_tvdss_m.1 | \n", "top_res_sstvd_m | \n", "top perfo tvd_ss_ft | \n", "z_wh_tvdss_m.1 | \n", "sensor_depth_tvdss | \n", "init_res_pr_bar | \n", "init_depletion_pr_bar | \n", "start_up_date | \n", "year_start | \n", "first_prod_days | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wellname | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| well_0 | \n", "WA12 | \n", "WA12 | \n", "Deltaic | \n", "B | \n", "B22 | \n", "B2 | \n", "None | \n", "WA | \n", "0.54 | \n", "0.39 | \n", "... | \n", "1077.26 | \n", "1036.50 | \n", "1063.72 | \n", "497.48 | \n", "962.016 | \n", "519.86 | \n", "4.04 | \n", "2006-12-01 | \n", "2006 | \n", "2191 | \n", "
| well_1 | \n", "JD28 | \n", "JD28 | \n", "Fluvial | \n", "D | \n", "D2 | \n", "D2 | \n", "None | \n", "JD | \n", "0.77 | \n", "0.23 | \n", "... | \n", "1115.73 | \n", "1003.26 | \n", "1087.60 | \n", "332.30 | \n", "982.500 | \n", "550.00 | \n", "1.01 | \n", "2014-05-01 | \n", "2014 | \n", "4899 | \n", "
| well_10 | \n", "SA29 | \n", "SA29_st1 | \n", "Fluvial | \n", "D | \n", "D3 | \n", "D1 | \n", "D2 | \n", "SA | \n", "0.64 | \n", "0.39 | \n", "... | \n", "1295.13 | \n", "1231.86 | \n", "1308.72 | \n", "626.28 | \n", "1209.727 | \n", "592.00 | \n", "4.63 | \n", "2011-08-01 | \n", "2011 | \n", "3895 | \n", "
| well_100 | \n", "RA08 | \n", "RA08 | \n", "Fluvial | \n", "D | \n", "D3 | \n", "D3 | \n", "None | \n", "RA | \n", "0.82 | \n", "0.26 | \n", "... | \n", "1511.14 | \n", "1507.18 | \n", "1444.31 | \n", "556.99 | \n", "1329.310 | \n", "680.00 | \n", "6.41 | \n", "2009-03-01 | \n", "2009 | \n", "3012 | \n", "
| well_101 | \n", "JB32 | \n", "JB32_st1 | \n", "Fluvial | \n", "D | \n", "D2 | \n", "D1 | \n", "None | \n", "JB | \n", "0.70 | \n", "0.32 | \n", "... | \n", "1171.23 | \n", "1105.51 | \n", "NaN | \n", "375.00 | \n", "NaN | \n", "490.00 | \n", "8.07 | \n", "2017-01-01 | \n", "2017 | \n", "5875 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| well_93 | \n", "YC13 | \n", "YC13 | \n", "Deltaic | \n", "B | \n", "B22 | \n", "B2 | \n", "None | \n", "YC | \n", "0.68 | \n", "0.30 | \n", "... | \n", "1166.93 | \n", "1093.93 | \n", "1131.87 | \n", "505.13 | \n", "1021.972 | \n", "540.00 | \n", "4.29 | \n", "2010-09-01 | \n", "2010 | \n", "3561 | \n", "
| well_94 | \n", "VD17 | \n", "VD17 | \n", "Deltaic | \n", "B | \n", "B22 | \n", "B2 | \n", "None | \n", "VD | \n", "0.64 | \n", "0.40 | \n", "... | \n", "1121.12 | \n", "1049.24 | \n", "1101.96 | \n", "511.04 | \n", "1039.875 | \n", "570.00 | \n", "0.94 | \n", "2003-03-01 | \n", "2003 | \n", "820 | \n", "
| well_95 | \n", "YA18 | \n", "YA18_st2 | \n", "Fluvial | \n", "E | \n", "E1 | \n", "E1 | \n", "None | \n", "YA | \n", "0.51 | \n", "0.41 | \n", "... | \n", "1452.83 | \n", "1463.29 | \n", "1480.16 | \n", "479.44 | \n", "1352.500 | \n", "670.00 | \n", "5.85 | \n", "2007-08-01 | \n", "2007 | \n", "2434 | \n", "
| well_97 | \n", "P136 | \n", "P136 | \n", "Fluvial | \n", "D | \n", "D3 | \n", "D3 | \n", "None | \n", "P1 | \n", "0.74 | \n", "0.30 | \n", "... | \n", "1301.07 | \n", "1309.64 | \n", "1329.15 | \n", "561.55 | \n", "1249.500 | \n", "657.00 | \n", "2.37 | \n", "2013-08-01 | \n", "2013 | \n", "4626 | \n", "
| well_99 | \n", "P302 | \n", "P302_st1 | \n", "Fluvial | \n", "D | \n", "D3 | \n", "D3 | \n", "None | \n", "P3 | \n", "0.73 | \n", "0.22 | \n", "... | \n", "1320.42 | \n", "1311.99 | \n", "1334.13 | \n", "535.87 | \n", "1246.300 | \n", "610.00 | \n", "5.68 | \n", "2016-08-01 | \n", "2016 | \n", "5722 | \n", "
176 rows × 38 columns
\n", "