Repository: scikit-learn/scikit-learn
File: sklearn/base.py (Python)

Code before:
                # k has no default value
                return True
            # avoid calling repr on nested estimators
            if isinstance(param_value, BaseEstimator) and type(param_value) is not type(
                init_default_params[param_name]
            ):
                return True
            if is_pandas_na(param_value) and not is_pandas_na(
                init_default_params[param_name]
            ):
                return True
            if not np.array_equal(
                param_value, init_default_params[param_name]
            ) and not (
                is_scalar_nan(init_default_params[param_name])
                and is_scalar_nan(param_value)
            ):
                return True

            return False

        # reorder the parameters from `self.get_params` using the `__init__`
        # signature
        remaining_params = [name for name in out if name not in init_default_params]
        ordered_dict = {name: out[name] for name in init_default_params if name in out}
        ordered_dict.update({name: out[name] for name in remaining_params})

        non_default_ls = tuple(
            [
                name
                for name, value in ordered_dict.items()
                if is_non_default(name, value)
            ]
        )

        output_dict = {
            name: out[name] for name in ordered_dict if name in non_default_ls
        }
        output_dict.update(
            {name: out[name] for name in ordered_dict if name not in non_default_ls}
        )

        return ParamsDict(
            params=output_dict,
            non_default=non_default_ls,
            estimator_class=self.__class__,
            doc_link=doc_link,
        )

    def set_params(self, **params):
        """Set the parameters of this estimator.

Review comment (suggestion):
```suggestion
        ordered_params = [name for name in init_default_params if name in out]
        ordered_params.extend(name for name in out if name not in init_default_params)
```

Code after:
                # k has no default value
                return True
            # avoid calling repr on nested estimators
            if isinstance(param_value, BaseEstimator) and type(param_value) is not type(
                init_default_params[param_name]
            ):
                return True
            if is_pandas_na(param_value) and not is_pandas_na(
                init_default_params[param_name]
            ):
                return True
            if not np.array_equal(
                param_value, init_default_params[param_name]
            ) and not (
                is_scalar_nan(init_default_params[param_name])
                and is_scalar_nan(param_value)
            ):
                return True

            return False

        # Sort parameters so non-default parameters are shown first
        unordered_params = {
            name: out[name] for name in init_default_params if name in out
        }
        unordered_params.update(
            {
                name: value
                for name, value in out.items()
                if name not in init_default_params
            }
        )

        non_default_params, default_params = [], []
        for name, value in unordered_params.items():
            if is_non_default(name, value):
                non_default_params.append(name)
            else:
                default_params.append(name)

        params = {name: out[name] for name in non_default_params + default_params}

        return ParamsDict(
            params=params,
            non_default=tuple(non_default_params),
            estimator_class=self.__class__,
            doc_link=doc_link,
        )

    def set_params(self, **params):
        """Set the parameters of this estimator.