def __init__(self, kdeType): """ Initialize the logger and ensure the requested KDE type exists. This uses the `statsmodels.nonparametric.kernel_density` library """ LOG.info("Initialising KDEParameters") kernels = kernel_switch.keys() if kdeType in kernels: LOG.debug("Using {0} to generate distribution".format(kdeType)) self.kdeType = kdeType else: LOG.error("Invalid kernel type: {0}".format(kdeType)) raise NotImplementedError( "Invalid kernel type: {0}".format(kdeType))
def __init__(self, kdeType): """ Initialize the logger and ensure the requested KDE type exists. This uses the `statsmodels.nonparametric.kernel_density` library """ LOG.info("Initialising KDEParameters") kernels = kernel_switch.keys() if kdeType in kernels: LOG.debug(f"Using {kdeType} to generate distribution") self.kdeType = kdeType else: msg = (f"Invalid kernel type: {kdeType} \n" f"Valid kernels are {repr(kernels)}") LOG.error(msg) raise NotImplementedError(msg)
color='red', zorder=20, label='Data samples', alpha=0.5) ax.legend(loc='best') ax.set_xlim([-3, 3]) ax.grid(True, zorder=-5) # ## Comparing kernel functions # In the example above, a Gaussian kernel was used. Several other kernels # are also available. from statsmodels.nonparametric.kde import kernel_switch list(kernel_switch.keys()) # ### The available kernel functions # Create a figure fig = plt.figure(figsize=(12, 5)) # Enumerate every option for the kernel for i, (ker_name, ker_class) in enumerate(kernel_switch.items()): # Initialize the kernel object kernel = ker_class() # Sample from the domain domain = kernel.domain or [-3, 3] x_vals = np.linspace(*domain, num=2**10)