.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/07_regression_kriging2d.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_examples_07_regression_kriging2d.py: Regression kriging ------------------ An example of regression kriging .. GENERATED FROM PYTHON SOURCE LINES 7-46 .. rst-class:: sphx-glr-script-out .. code-block:: none ======================================== regression model: SVR Finished learning regression model Finished kriging residuals Regression Score: -0.03405385545698292 RK score: 0.6706182225388981 ======================================== regression model: RandomForestRegressor Finished learning regression model Finished kriging residuals Regression Score: 0.7041419269689924 RK score: 0.7415694880137507 ======================================== regression model: LinearRegression Finished learning regression model Finished kriging residuals Regression Score: 0.5277968398381674 RK score: 0.6036605153133718 | .. code-block:: Python import sys from sklearn.datasets import fetch_california_housing from sklearn.ensemble import RandomForestRegressor from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from sklearn.svm import SVR from pykrige.rk import RegressionKriging svr_model = SVR(C=0.1, gamma="auto") rf_model = RandomForestRegressor(n_estimators=100) lr_model = LinearRegression(copy_X=True, fit_intercept=False) models = [svr_model, rf_model, lr_model] try: housing = fetch_california_housing() except PermissionError: # this dataset can occasionally fail to download on Windows sys.exit(0) # take the first 5000 as Kriging is memory intensive p = housing["data"][:5000, :-2] x = housing["data"][:5000, -2:] target = housing["target"][:5000] p_train, p_test, x_train, x_test, target_train, target_test = train_test_split( p, x, target, test_size=0.3, random_state=42 ) for m in models: print("=" * 40) print("regression model:", m.__class__.__name__) m_rk = RegressionKriging(regression_model=m, n_closest_points=10) m_rk.fit(p_train, x_train, target_train) print("Regression Score: ", m_rk.regression_model.score(p_test, target_test)) print("RK score: ", m_rk.score(p_test, x_test, target_test)) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.571 seconds) .. _sphx_glr_download_examples_07_regression_kriging2d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 07_regression_kriging2d.ipynb <07_regression_kriging2d.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 07_regression_kriging2d.py <07_regression_kriging2d.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 07_regression_kriging2d.zip <07_regression_kriging2d.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_