code: def _group_models(self):
          od = OrderedDict()
          for i, model in enumerate(self.models):
              output = getattr(model, "output", {})
              if output.get("AIC") and output.get("BMD") and output["BMD"] > 0:
                  key = "{}-{}".format(output["AIC"], output["BMD"])
                  if key in od:
                      od[key].append(model)
                  else:
                      od[key] = [model]
              else:
                  od[i] = [model]
          def _get_num_params(model):
              return (
                  len(model.output["parameters"])
                  if hasattr(model, "output") and "parameters" in model.output
                  else 0
              )
          for key, _models in od.items():
              _models.sort(key=_get_num_params)
          return list(od.values())