Class: Rover::DataFrame

Inherits:
Object
  • Object
show all
Defined in:
lib/hybridforest/utilities/utils.rb

Instance Method Summary collapse

Instance Method Details

#class_labelsObject



160
161
162
# File 'lib/hybridforest/utilities/utils.rb', line 160

def class_labels
  self[label].to_a
end

#column_by_index(index) ⇒ Object



135
136
137
138
# File 'lib/hybridforest/utilities/utils.rb', line 135

def column_by_index(index)
  where = @vectors.keys[index]
  @vectors[where]
end

#count_labelsObject



152
153
154
# File 'lib/hybridforest/utilities/utils.rb', line 152

def count_labels
  self[label].tally
end

#disconnect_labelsObject



164
165
166
167
168
# File 'lib/hybridforest/utilities/utils.rb', line 164

def disconnect_labels
  labels = class_labels
  except!(label)
  [self, labels]
end

#equal_or_greater_split(feature, value) ⇒ Object



121
122
123
124
125
# File 'lib/hybridforest/utilities/utils.rb', line 121

def equal_or_greater_split(feature, value)
  equal_or_greater = self[self[feature] >= value]
  less = self[self[feature] < value]
  [equal_or_greater, less]
end

#equal_split(feature, value) ⇒ Object



115
116
117
118
119
# File 'lib/hybridforest/utilities/utils.rb', line 115

def equal_split(feature, value)
  equal = self[self[feature] == value]
  not_equal = self[!self[feature].in?([value])]
  [equal, not_equal]
end

#feature_count(without_label: true) ⇒ Object



140
141
142
# File 'lib/hybridforest/utilities/utils.rb', line 140

def feature_count(without_label: true)
  without_label ? features.count : names.count
end

#featuresObject



148
149
150
# File 'lib/hybridforest/utilities/utils.rb', line 148

def features
  names[0...-1]
end

#labelObject



156
157
158
# File 'lib/hybridforest/utilities/utils.rb', line 156

def label
  names[-1]
end

#multiway_equal_split(feature) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/hybridforest/utilities/utils.rb', line 127

def multiway_equal_split(feature)
  subsets = []
  self[feature].uniq.each do |value|
    subsets << self[self[feature] == value]
  end
  subsets
end

#pure?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/hybridforest/utilities/utils.rb', line 144

def pure?
  self[label].uniq.size == 1
end