def set_index_type(self, index_type, leaf_size=30):
        """
        Set the index type for the KNearestNeighborsClassifier model.

        Parameters
        ----------
        index_type
                One of [ ``'linear'``, ``'kd_tree'`` ].

        leaf_size
                For kd_tree indexes, the leaf size to use (default = 30).

        Returns
        -------
        None
        """
        index_type = index_type.lower()
        if index_type not in self._VALID_INDEX_TYPES:
            raise TypeError("Invalid index type")

        if index_type == "kd_tree":
            if leaf_size <= 0:
                raise TypeError("leaf_size must be > 0")
            self.spec.kNearestNeighborsClassifier.nearestNeighborsIndex.singleKdTreeIndex.leafSize = (
                leaf_size
            )
        else:
            self.spec.kNearestNeighborsClassifier.nearestNeighborsIndex.linearIndex.MergeFromString(
                b""
            )

        # storing this in the object is just a convenience
        self._index_type = index_type

        Set the index type for the KNearestNeighborsClassifier model.

        Parameters
        ----------
        index_type
                One of [ ``'linear'``, ``'kd_tree'`` ].

        leaf_size
                For kd_tree indexes, the leaf size to use (default = 30).

        Returns
        -------
        None
        
coremltools/models/nearest_neighbors/builder.py