ankane / isotree-ruby

Outlier/anomaly detection for Ruby using Isolation Forest
BSD 2-Clause "Simplified" License
30 stars 3 forks source link

Ideas #1

Open ankane opened 4 years ago

ankane commented 4 years ago

Ideas

kenhys commented 3 years ago

export_model, import_model

It is the feature that I want to use. Maybe serialize_ext_isoforest and deserialize_ext_isoforest must be wrapped.

diff --git a/ext/isotree/ext.cpp b/ext/isotree/ext.cpp                                                                                      
index 62a37a8..bc2ee11 100644                                                                                                               
--- a/ext/isotree/ext.cpp                                                                                                                   
+++ b/ext/isotree/ext.cpp                                                                                                                   
@@ -1,4 +1,5 @@                                                                                                                             
 // isotree
+#define _ENABLE_CEREAL                                                                                                                     
 #include <isotree.hpp>

 // rice
@@ -259,5 +260,18 @@ void Init_ext()                                                                                                        
           ret.push(outlier_scores[i]);
         }
         return ret;
+      })                                                                                                                                   
+    .define_singleton_method(                                                                                                              
+      "serialize_iforest",                                                                                                                 
+      *[](ExtIsoForest& iso, String path) {                                                                                                
+        serialize_ext_isoforest(iso, path.c_str());                                                                                        
+        return iso;                                                                                                                        
+      })                                                                                                                                   
+    .define_singleton_method(                                                                                                              
+      "deserialize_iforest",                                                                                                               
+      *[](String path) {                                                                                                                   
+        ExtIsoForest iso;                                                                                                                  
+        deserialize_ext_isoforest(iso, path.c_str());                                                                                      
+        return iso;                                                                                                                        
       });
 }
ankane commented 3 years ago

Hey @kenhys, there's now a very basic version in the export_model branch.

Edit: Think it's in a good place now, so merged to master.

kenhys commented 3 years ago

Thanks, I'll try it.