<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def kde(self, term, bandwidth=2000, samples=1000, kernel='gaussian'):
 """ Estimate the kernel density of the instances of term in the text. Args: term (str):
 A stemmed term. bandwidth (int):
 The kernel bandwidth. samples (int):
 The number of evenly-spaced sample points. kernel (str):
 The kernel function. Returns: np.array: The density estimate. """


        # Get the offsets of the term instances.
        terms = np.array(self.terms[term])[:, np.newaxis]

        # Fit the density estimator on the terms.
        kde = KernelDensity(kernel=kernel, bandwidth=bandwidth).fit(terms)

        # Score an evely-spaced array of samples.
        x_axis = np.linspace(0, len(self.tokens), samples)[:, np.newaxis]
        scores = kde.score_samples(x_axis)

        # Scale the scores to integrate to 1.
        return np.exp(scores) * (len(self.tokens) / samples)