INNER CODE UNIT · Ruby

load_libsvm_file

yoshoku/rumale · rumale-core/lib/rumale/dataset.rb:22

      def load_libsvm_file(filename, n_features: nil, zero_based: false, dtype: Numo::DFloat)
        ftvecs = []
        labels = []
        n_features_detected = 0
        CSV.foreach(filename, col_sep: "\s", headers: false) do |line|
          label, ftvec, max_idx = parse_libsvm_line(line, zero_based)
          labels.push(label)
          ftvecs.push(ftvec)
          n_features_detected = max_idx if n_features_detected < max_idx
        end
        n_features ||= n_features_detected
        n_features = [n_features, n_features_detected].max
        [convert_to_matrix(ftvecs, n_features, dtype), Numo::NArray.asarray(labels)]
      end

      # Dump the dataset with the libsvm file format.
      #
      # @param data [Numo::NArray] (shape: [n_samples, n_features]) matrix consisting of feature vectors.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…