def fit(
        self,
        frequency,
        recency,
        n_periods,
        weights=None,
        initial_params=None,
        verbose=False,
        tol=1e-7,
        index=None,
        **kwargs
    ):
        """
        Fit the BG/BB model.

        Parameters
        ----------
        frequency: array_like
            Total periods with observed transactions
        recency: array_like
            Period of most recent transaction
        n_periods: array_like
            Number of transaction opportunities. Previously called `n`.
        weights: None or array_like
            Number of customers with given frequency/recency/T,
            defaults to 1 if not specified. Fader and
            Hardie condense the individual RFM matrix into all
            observed combinations of frequency/recency/T. This
            parameter represents the count of customers with a given
            purchase pattern. Instead of calculating individual
            log-likelihood, the log-likelihood is calculated for each
            pattern and multiplied by the number of customers with
            that pattern.  Previously called `n_custs`.
        verbose: boolean, optional
            Set to true to print out convergence diagnostics.
        tol: float, optional
            Tolerance for termination of the function minimization process.
        index: array_like, optional
            Index for resulted DataFrame which is accessible via self.data
        kwargs:
            Key word arguments to pass to the scipy.optimize.minimize
            function as options dict

        Returns
        -------
        BetaGeoBetaBinomFitter
            fitted and with parameters estimated

        """
        frequency = np.asarray(frequency).astype(int)
        recency = np.asarray(recency).astype(int)
        n_periods = np.asarray(n_periods).astype(int)

        if weights is None:
            weights = np.ones_like(recency)
        else:
            weights = np.asarray(weights)

        _check_inputs(frequency, recency, n_periods)

        log_params_, self._negative_log_likelihood_, self._hessian_ = self._fit(
            (frequency, recency, n_periods, weights, self.penalizer_coef), initial_params, 4, verbose, tol, **kwargs
        )
        self.params_ = pd.Series(np.exp(log_params_), index=["alpha", "beta", "gamma", "delta"])

        self.data = DataFrame(
            {"frequency": frequency, "recency": recency, "n_periods": n_periods, "weights": weights}, index=index
        )

        self.generate_new_data = lambda size=1: beta_geometric_beta_binom_model(
            # Making a large array replicating n by n_custs having n.
            np.array(sum([n_] * n_cust for (n_, n_cust) in zip(n_periods, weights))),
            *self._unload_params("alpha", "beta", "gamma", "delta"),
            size=size
        )

        self.variance_matrix_ = self._compute_variance_matrix()
        self.standard_errors_ = self._compute_standard_errors()
        self.confidence_intervals_ = self._compute_confidence_intervals()
        return self
Fit the BG/BB model.

        Parameters
        ----------
        frequency: array_like
            Total periods with observed transactions
        recency: array_like
            Period of most recent transaction
        n_periods: array_like
            Number of transaction opportunities. Previously called `n`.
        weights: None or array_like
            Number of customers with given frequency/recency/T,
            defaults to 1 if not specified. Fader and
            Hardie condense the individual RFM matrix into all
            observed combinations of frequency/recency/T. This
            parameter represents the count of customers with a given
            purchase pattern. Instead of calculating individual
            log-likelihood, the log-likelihood is calculated for each
            pattern and multiplied by the number of customers with
            that pattern.  Previously called `n_custs`.
        verbose: boolean, optional
            Set to true to print out convergence diagnostics.
        tol: float, optional
            Tolerance for termination of the function minimization process.
        index: array_like, optional
            Index for resulted DataFrame which is accessible via self.data
        kwargs:
            Key word arguments to pass to the scipy.optimize.minimize
            function as options dict

        Returns
        -------
        BetaGeoBetaBinomFitter
            fitted and with parameters estimated