Class: IsoTree::IsolationForest
- Inherits:
-
Object
- Object
- IsoTree::IsolationForest
- Defined in:
- lib/isotree/isolation_forest.rb
Instance Method Summary collapse
- #fit(x) ⇒ Object
-
#initialize(sample_size: nil, ntrees: 500, ndim: 3, ntry: 3, prob_pick_avg_gain: 0, prob_pick_pooled_gain: 0, prob_split_avg_gain: 0, prob_split_pooled_gain: 0, min_gain: 0, all_perm: false, coef_by_prop: false, sample_with_replacement: false, penalize_range: true, weigh_by_kurtosis: false, min_imp_obs: 3, random_seed: 1, nthreads: -1) ⇒ IsolationForest
constructor
A new instance of IsolationForest.
- #predict(x) ⇒ Object
Constructor Details
#initialize(sample_size: nil, ntrees: 500, ndim: 3, ntry: 3, prob_pick_avg_gain: 0, prob_pick_pooled_gain: 0, prob_split_avg_gain: 0, prob_split_pooled_gain: 0, min_gain: 0, all_perm: false, coef_by_prop: false, sample_with_replacement: false, penalize_range: true, weigh_by_kurtosis: false, min_imp_obs: 3, random_seed: 1, nthreads: -1) ⇒ IsolationForest
Returns a new instance of IsolationForest.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/isotree/isolation_forest.rb', line 3 def initialize( sample_size: nil, ntrees: 500, ndim: 3, ntry: 3, prob_pick_avg_gain: 0, prob_pick_pooled_gain: 0, prob_split_avg_gain: 0, prob_split_pooled_gain: 0, min_gain: 0, all_perm: false, coef_by_prop: false, sample_with_replacement: false, penalize_range: true, weigh_by_kurtosis: false, min_imp_obs: 3, random_seed: 1, nthreads: -1 ) @sample_size = sample_size @ntrees = ntrees @ndim = ndim @ntry = ntry @prob_pick_avg_gain = prob_pick_avg_gain @prob_pick_pooled_gain = prob_pick_pooled_gain @prob_split_avg_gain = prob_split_avg_gain @prob_split_pooled_gain = prob_split_pooled_gain @min_gain = min_gain @all_perm = all_perm @coef_by_prop = coef_by_prop @sample_with_replacement = sample_with_replacement @penalize_range = penalize_range @weigh_by_kurtosis = weigh_by_kurtosis @min_imp_obs = min_imp_obs @random_seed = random_seed # etc module returns virtual cores nthreads = Etc.nprocessors if nthreads < 0 @nthreads = nthreads end |
Instance Method Details
#fit(x) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/isotree/isolation_forest.rb', line 34 def fit(x) = (x).merge() [:sample_size] ||= [:nrows] @ncols = [:ncols] @ext_iso_forest = Ext.fit_iforest() end |
#predict(x) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/isotree/isolation_forest.rb', line 41 def predict(x) raise "Not fit" unless @ext_iso_forest = (x).merge(nthreads: @nthreads) if [:ncols] != @ncols raise ArgumentError, "Input must have #{@ncols} columns for this model" end Ext.predict_iforest(@ext_iso_forest, ) end |