<jupyter_start><jupyter_text>Estimate a VariogramUse the geostatistics toolbox to estimate a variogram and use one of the manyplots. These plots help to understand the spatial properties of a variogram,and finally, the :class:`Variogram ` object itself can bereturned and used in one of the Kriging routines.<jupyter_code>from pprint import pprint
import plotly
import hydrobox
from hydrobox.data import pancake
from hydrobox.plotting import plotting_backend
plotting_backend('plotly')<jupyter_output><empty_output><jupyter_text>Load sample data from the data sub-module<jupyter_code>df = pancake()<jupyter_output><empty_output><jupyter_text>Estimate a variogram using a exponential model and 25 distance lagsthat are derived from a KMeans cluster algorithmHere, we use the describe output option to get a dictionary of all variogram parameters<jupyter_code>vario = hydrobox.geostat.variogram(
    coordinates=df[['x', 'y']].values,
    values=df.z.values,
    model='exponential',
    bin_func='kmeans',
    n_lags=25,
    return_type='describe'
)
# print
pprint(vario)<jupyter_output><empty_output><jupyter_text>There are various return types, one of them is the plot.This is the main plotting tool for variogram instances<jupyter_code>fig = hydrobox.geostat.variogram(
    coordinates=df[['x', 'y']].values,
    values=df.z.values,
    model='exponential',
    bin_func='kmeans',
    n_lags=25,
    return_type='plot'
)

# show the figure
plotly.io.show(fig)<jupyter_output><empty_output><jupyter_text>Alternatively you can return the :class:`Variogram `object itself and use all the different settings and methods directly.<jupyter_code>v = hydrobox.geostat.variogram(
    coordinates=df[['x', 'y']].values,
    values=df.z.values,
    model='exponential',
    bin_func='kmeans',
    n_lags=25,
    return_type='object'
)

pprint(v)<jupyter_output><empty_output><jupyter_text>The :class:`Variogram ` has a plotting method forall point pairs at their separating distances. It is available as a return type, but can also be called directly:<jupyter_code>fig = v.distance_difference_plot() 

plotly.io.show(fig)<jupyter_output><empty_output><jupyter_text>The variogram instance has a lot of quality measures to judge the goodnessof fit for the theoretical model. They are implemented as properties and canbe used like attribtues, while being always up to date if the variogram is mutated.Another helpful method is :func:`cross_validate `.This will run a leave-one-out cross validation by interpolating the missing point for all points. This is especially useful in cases, where a theoretical model fits well,but the spatial properties are not well captured.<jupyter_code># calculate the rmse of the model
print(f"{v.model.__name__} RMSE:  {v.rmse}")

# get the cross-validation time
from time import time
t1 = time()
rmse = v.cross_validate()
t2 = time()
print('Cross-validated RMSE: %.2f  (took: %2fs)' % (rmse, t2 - t1))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09041652556721978, 'fraction_numerical': 0.004740941415509651, 'mean_word_length': 5.7908045977011495, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '635103', 'license': 'MIT', 'n_tokens_mistral': 946, 'n_tokens_neox': 912, 'n_words': 295, 'path': 'doc/auto_examples/geostat/plot_variogram.ipynb', 'repo_name': 'VForWaTer/hydrobox', 'size': '2953'}