def _cluster_data_object(self, x, y=None): """ Sends a data objected encoded as a numpy array or a list and cluster it """ self._send_array(x, y) cluster, distance = SubCMediansWrapper_c.clusterize_SubCMedianspoint_with_model( self._p_subcmedians_c, self._data_object) return [int(y), cluster], distance
def _transform_array(self, x): """ Apply the transform function to objects x in order to compute the distance to each candidate center in the model. """ self._send_array(x) cluster, distance = SubCMediansWrapper_c.clusterize_SubCMedianspoint_with_model( self._p_subcmedians_c, self._data_object) SubCMediansWrapper_c.get_distances_to_core_point( cluster, self._p_subcmedians_c, self._data_object, self._distances_to_cluster_getter) return array(self._distances_to_cluster_getter)
def score(self, X): """ Compute the mean intra-cluster distance """ X_ = self._check_X_matrix_validity(X) scores = [] for i, x in enumerate(X_): self._send_array(x) cluster, distance = SubCMediansWrapper_c.clusterize_SubCMedianspoint_with_model( self._p_subcmedians_c, self._data_object) scores.append(distance) return np.asarray(scores).mean()
def predict(self, X): """ sklearn-like predict function, receives a dataset and compute the cluster membership of its data objects """ X_ = self._check_X_matrix_validity(X) Y_ = array([]) for i, x in enumerate(X_): self._send_array(x) cluster, distance = SubCMediansWrapper_c.clusterize_SubCMedianspoint_with_model( self._p_subcmedians_c, self._data_object) Y_ = append(Y_, cluster) return Y_