'Fits the model by maximum likelihood via Hamilton filter.
Parameters
start_params : array_like, optional
Initial guess of the solution for the loglikelihood maximization.
If None, the default is given by Model.start_params.
transformed : boolean, optional
Whether or not `start_params` is already transformed. Default is
True.
cov_type : str, optional
The type of covariance matrix estimator to use. Can be one of
\'approx\', \'opg\', \'robust\', or \'none\'. Default is \'approx\'.
cov_kwds : dict or None, optional
Keywords for alternative covariance estimators
method : str, optional
The `method` determines which solver from `scipy.optimize`
is used, and it can be chosen from among the following strings:
- \'newton\' for Newton-Raphson, \'nm\' for Nelder-Mead
- \'bfgs\' for Broyden-Fletcher-Goldfarb-Shanno (BFGS)
- \'lbfgs\' for limited-memory BFGS with optional box constraints
- \'powell\' for modified Powell\'s method
- \'cg\' for conjugate gradient
- \'ncg\' for Newton-conjugate gradient
- \'basinhopping\' for global basin-hopping solver
The explicit arguments in `fit` are passed to the solver,
with the exception of the basin-hopping solver. Each
solver has several optional arguments that are not the same across
solvers. See the notes section below (or scipy.optimize) for the
available arguments and for the list of explicit arguments that the
basin-hopping solver supports.
maxiter : int, optional
The maximum number of iterations to perform.
full_output : boolean, optional
Set to True to have all available output in the Results object\'s
mle_retvals attribute. The output is dependent on the solver.
See LikelihoodModelResults notes section for more information.
disp : boolean, optional
Set to True to print convergence messages.
callback : callable callback(xk), optional
Called after each iteration, as callback(xk), where xk is the
current parameter vector.
return_params : boolean, optional
Whether or not to return only the array of maximizing parameters.
Default is False.
em_iter : int, optional
Number of initial EM iteration steps used to improve starting
parameters.
search_reps : int, optional
Number of randomly drawn search parameters that are drawn around
`start_params` to try and improve starting parameters. Default is
0.
search_iter : int, optional
Number of initial EM iteration steps used to improve each of the
search parameter repetitions.
search_scale : float or array, optional.
Scale of variates for random start parameter search.
**kwargs
Additional keyword arguments to pass to the optimizer.
Returns
MarkovSwitchingResults'

def fit(self, start_params=None, transformed=True, cov_type='approx', cov_kwds=None, method='bfgs', maxiter=100, full_output=1, disp=0, callback=None, return_params=False, em_iter=5, search_reps=0, search_iter=5, search_scale=1.0, **kwargs):

    if (start_params is None):
        start_params = self.start_params
        transformed = True
    else:
        start_params = np.array(start_params, ndmin=1)
    if (search_reps > 0):
        start_params = self._start_params_search(search_reps, start_params=start_params, transformed=transformed, em_iter=search_iter, scale=search_scale)
        transformed = True
    if (em_iter and (not self.tvtp)):
        start_params = self._fit_em(start_params, transformed=transformed, maxiter=em_iter, tolerance=0, return_params=True)
        transformed = True
    if transformed:
        start_params = self.untransform_params(start_params)
    fargs = (False,)
    mlefit = super(MarkovSwitching, self).fit(start_params, method=method, fargs=fargs, maxiter=maxiter, full_output=full_output, disp=disp, callback=callback, skip_hessian=True, **kwargs)
    if return_params:
        result = self.transform_params(mlefit.params)
    else:
        result = self.smooth(mlefit.params, transformed=False, cov_type=cov_type, cov_kwds=cov_kwds)
        result.mlefit = mlefit
        result.mle_retvals = mlefit.mle_retvals
        result.mle_settings = mlefit.mle_settings
    return result
