def train(self, input_train, target_train, copy=True): """ Trains network. PNN doesn't actually train, it just stores input data and use it for prediction. Parameters ---------- input_train : array-like (n_samples, n_features) target_train : array-like (n_samples,) Target variable should be vector or matrix with one feature column. copy : bool If value equal to ``True`` than input matrices will be copied. Defaults to ``True``. Raises ------ ValueError In case if something is wrong with input data. """ input_train = format_data(input_train, copy=copy) target_train = format_data(target_train, copy=copy) n_target_features = target_train.shape[1] if n_target_features != 1: raise ValueError("Target value must be one dimensional array") LazyLearningMixin.train(self, input_train, target_train)
def train(self, input_train, target_train, copy=True): """ Trains network. PNN doesn't actually train, it just stores input data and use it for prediction. Parameters ---------- input_train : array-like (n_samples, n_features) target_train : array-like (n_samples,) Target variable should be vector or matrix with one feature column. copy : bool If value equal to ``True`` than input matrices will be copied. Defaults to ``True``. Raises ------ ValueError In case if something is wrong with input data. """ input_train = format_data(input_train, copy=copy) target_train = format_data(target_train, copy=copy) LazyLearningMixin.train(self, input_train, target_train) n_target_features = target_train.shape[1] if n_target_features != 1: raise ValueError("Target value should be a vector or a " "matrix with one column") classes = self.classes = np.unique(target_train) n_classes = classes.size n_samples = input_train.shape[0] row_comb_matrix = self.row_comb_matrix = np.zeros( (n_classes, n_samples) ) class_ratios = self.class_ratios = np.zeros(n_classes) for i, class_name in enumerate(classes): class_val_positions = (target_train == i) row_comb_matrix[i, class_val_positions.ravel()] = 1 class_ratios[i] = np.sum(class_val_positions)