Skip to content

[ENH] Improve _check_params method in _k_means.py and _k_medoids.py #2681

Open
@tanishy7777

Description

@tanishy7777

Describe the feature or idea you want to propose

Right now there is no else condition in the _check_params function if the self.init is a string.

def _check_params(self, X: np.ndarray) -> None:
        self._random_state = check_random_state(self.random_state)

        if isinstance(self.init, str):
            if self.init == "random":
                self._init = self._random_center_initializer
            elif self.init == "kmedoids++":
                self._init = self._kmedoids_plus_plus_center_initializer
            elif self.init == "first":
                self._init = self._first_center_initializer
            elif self.init == "build":
                self._init = self._pam_build_center_initializer
        else:
          # other code

So when we pass a string other than the expected strings it leads to an error which is not very user friendly.
Would be nice to let the user know what the cause of the error is.

Also noticed that the build initialization doesn't have any documentation. Would be good to at that as well?

Describe your proposed solution

add an else statement

Describe alternatives you've considered, if relevant

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    clusteringClustering packageenhancementNew feature, improvement request or other non-bug code enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions