Sha256: 6a534a062a57a0fe0a3aa4041b7547b2ac67fcb7f59665e91b1e59fac48732ce
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
# Turns a data frame into ARFF-formatted content. module ARFF # Used in arff, but generally useful. def to_csv(include_header=true) value = include_header ? self.labels.map{|e| e.to_s}.join(',') + "\n" : '' self.items.inject(value) do |list, e| list << e.map {|cell| cell.to_s}.join(',') + "\n" end end def to_arff arff_header + to_csv(false) end protected def arff_attributes container = defined?(Dictionary) ? Dictionary.new : Hash.new self.labels.inject(container) do |list, e| list[e] = self.render_column(e).categories end end def arff_formatted_attributes self.labels.inject('') do |str, e| val = "{" + self.render_column(e).categories.map{|x| x.to_s}.join(',') + "}" str << "@attribute #{e} #{val}\n" end end def arff_relation self.name ? self.name.to_underscore_sym.to_s : 'unamed_relation' end def arff_header %[@relation #{arff_relation} #{arff_formatted_attributes} @data ] end alias :arff_items :to_csv end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
davidrichards-data_frame-0.0.18 | lib/data_frame/arff.rb |