.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/experiments.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_experiments.py: =============== Experiments =============== .. GENERATED FROM PYTHON SOURCE LINES 6-15 .. code-block:: Python import matplotlib.pyplot as plt from ai4water.experiments import MLRegressionExperiments from utils import prepare_data, SAVE from utils import set_rcParams from utils import print_version_info .. GENERATED FROM PYTHON SOURCE LINES 16-18 .. code-block:: Python print_version_info() .. rst-class:: sphx-glr-script-out .. code-block:: none python 3.12.7 (main, Nov 5 2024, 16:16:58) [GCC 11.4.0] os posix ai4water 1.07 xgboost 2.1.3 easy_mpl 0.21.4 SeqMetrics 2.0.0 torch 2.5.1+cu124 numpy 1.26.4 pandas 1.5.3 matplotlib 3.8.4 sklearn 1.3.1 xarray 2024.3.0 netCDF4 1.7.2 seaborn 0.13.2 bnlearn 0.10.2 Script Executed on: Wed Jan 1 06:31:17 2025 tot_cpus 2 avail_cpus 2 mem_gib 7.612831115722656 .. GENERATED FROM PYTHON SOURCE LINES 19-21 .. code-block:: Python set_rcParams() .. GENERATED FROM PYTHON SOURCE LINES 22-25 .. code-block:: Python data, _, _ = prepare_data() .. GENERATED FROM PYTHON SOURCE LINES 26-36 .. code-block:: Python comparisons = MLRegressionExperiments( input_features=data.columns.tolist()[0:-1], output_features=data.columns.tolist()[-1:], split_random=True, seed=1575, verbosity=0, show=False ) .. GENERATED FROM PYTHON SOURCE LINES 37-53 .. code-block:: Python comparisons.fit( data=data, run_type="dry_run", include=['XGBRegressor', 'AdaBoostRegressor', 'LinearSVR', 'BaggingRegressor', 'DecisionTreeRegressor', 'HistGradientBoostingRegressor', 'ExtraTreesRegressor', 'ExtraTreeRegressor', 'LinearRegression', 'KNeighborsRegressor', 'RandomForestRegressor', 'SGDRegressor', 'SVR', 'LassoCV', 'RidgeCV', ] ) .. rst-class:: sphx-glr-script-out .. code-block:: none ***** Training ***** input_x shape: (584, 14) target shape: (584, 1) ***** Validation ***** input_x shape: (146, 14) target shape: (146, 1) ***** Test ***** input_x shape: (314, 14) target shape: (314, 1) running XGBRegressor model running AdaBoostRegressor model running LinearSVR model running BaggingRegressor model running DecisionTreeRegressor model running HistGradientBoostingRegressor model running ExtraTreesRegressor model running ExtraTreeRegressor model running LinearRegression model running KNeighborsRegressor model running RandomForestRegressor model running SGDRegressor model running SVR model running LassoCV model running RidgeCV model .. GENERATED FROM PYTHON SOURCE LINES 54-70 .. code-block:: Python set_rcParams({'xtick.labelsize': '14', 'ytick.labelsize': '14'}) _ = comparisons.compare_errors( 'r2', data=data, colors=('#063970', '#e28743'), figsize=(8, 8), ) fig = plt.gcf() fig.text(0.35, 0.95, 'a)', ha='center', fontsize=14) fig.text(0.7, 0.95, 'b)', ha='center', fontsize=14) plt.tight_layout() # plt.savefig("../manuscript/figures/figS1.png", dpi=600, bbox_inches="tight") plt.show() .. image-sg:: /auto_examples/images/sphx_glr_experiments_001.png :alt: Training, Test :srcset: /auto_examples/images/sphx_glr_experiments_001.png, /auto_examples/images/sphx_glr_experiments_001_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ***** Training ***** input_x shape: (584, 14) target shape: (584, 1) ***** Validation ***** input_x shape: (146, 14) target shape: (146, 1) ***** Test ***** input_x shape: (314, 14) target shape: (314, 1) .. GENERATED FROM PYTHON SOURCE LINES 71-82 .. code-block:: Python r2_score = comparisons.compare_errors( 'r2_score', data=data, figsize=(8, 10), cutoff_type='greater', cutoff_val=0.5, colors=('#063970', '#e28743') ) plt.tight_layout() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_experiments_002.png :alt: Training, Test :srcset: /auto_examples/images/sphx_glr_experiments_002.png, /auto_examples/images/sphx_glr_experiments_002_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ***** Training ***** input_x shape: (584, 14) target shape: (584, 1) ***** Validation ***** input_x shape: (146, 14) target shape: (146, 1) ***** Test ***** input_x shape: (314, 14) target shape: (314, 1) .. GENERATED FROM PYTHON SOURCE LINES 83-95 .. code-block:: Python rmse = comparisons.compare_errors( 'rmse', data=data, figsize=(8, 10), cutoff_type='less', cutoff_val=1000, colors=('#063970', '#e28743') ) plt.tight_layout() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_experiments_003.png :alt: Training, Test :srcset: /auto_examples/images/sphx_glr_experiments_003.png, /auto_examples/images/sphx_glr_experiments_003_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ***** Training ***** input_x shape: (584, 14) target shape: (584, 1) ***** Validation ***** input_x shape: (146, 14) target shape: (146, 1) ***** Test ***** input_x shape: (314, 14) target shape: (314, 1) .. GENERATED FROM PYTHON SOURCE LINES 96-112 .. code-block:: Python figure = comparisons.taylor_plot( data=data, figsize=(8, 8), include=r2_score.index.tolist(), leg_kws={'facecolor': 'white', 'edgecolor': 'black', 'bbox_to_anchor':(1.0, 0.9), 'fontsize': 10, 'labelspacing': 1.0, 'ncol': 1 }, ) figure.axes[0].axis['left'].label.set_text('') figure.axes[0].set_title('Training') if SAVE: plt.savefig("results/figures/exp_taylor.png", dpi=600, bbox_inches="tight") plt.tight_layout() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_experiments_004.png :alt: , Training, Test :srcset: /auto_examples/images/sphx_glr_experiments_004.png, /auto_examples/images/sphx_glr_experiments_004_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ***** Training ***** input_x shape: (584, 14) target shape: (584, 1) ***** Validation ***** input_x shape: (146, 14) target shape: (146, 1) ***** Test ***** input_x shape: (314, 14) target shape: (314, 1) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 36.767 seconds) .. _sphx_glr_download_auto_examples_experiments.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: experiments.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: experiments.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: experiments.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_