Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Isolation forest implementation in Go

License

NotificationsYou must be signed in to change notification settings

e-XpertSolutions/go-iforest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDocLicenseGoReportTraviscover.run go

Go implementation of Isolation Forest algorithm.

Isolation Forest is an unsupervised learning algorithm that is able to detect anomalies (data patterns that differ from normal instances). Detection is performed by recursive data partitioning, which can be represented by a tree structure. At each iteration data is splitted using randomly chosen feature and its value (random number between maximum and minimum value of chosen feature). Due to the fact that anomalies are rare and different from other instances, smaller number of partitions is needed to isolate them. This is equivalent to the path length in created tree. Shorter path means that given instance can be an anomaly. To improve accuracy the ensemble of such trees is created and result is averaged over all trees.

To get more information about algorithm, please refer to this paper:IFOREST.

Installation

Stable release can be downloaded by issuing the following command:

go get github.com/e-XpertSolutions/go-iforest/v2

Usage

This example shows how to use the Isolation Forest. You will need to load the data, initialize iforest with proper parameters and use two functions: Train(), Test() to create the model. First one is used to build the trees, second one to find proper "anomaly threshold" and detect anomalies in given data. After that you can pass new instances to Predict() which result in labeling them as normal "0" or anomaly "1".It is possible to use parallel versions of testing and detecting functions - they use multiple go routines to speed up computations.Created models can be saved and read from the files using Save() and Load() methods.

package mainimport("fmt""github.com/e-XpertSolutions/go-iforest/iforest")funcmain(){// input data must be loaded into two dimensional array of the type float64// please note: loadData() is some custom function - not included in the// libraryvarinputData [][]float64inputData=loadData("filename")// input parameterstreesNumber:=100subsampleSize:=256outliersRatio:=0.01routinesNumber:=10//model initializationforest:=iforest.NewForest(treesNumber,subsampleSize,outliers)//training stage - creating treesforest.Train(inputData)//testing stage - finding anomalies//Test or TestParaller can be used, concurrent version needs one additional// parameterforest.Test(inputData)forest.TestParallel(inputData,routinesNumber)//after testing it is possible to access anomaly scores, anomaly bound// and labels for the input datasetthreshold:=forest.AnomalyBoundanomalyScores:=forest.AnomalyScoreslabelsTest:=forest.Labels//to get information about new instances pass them to the Predict function// to speed up computation use concurrent version of PredictvarnewData [][]float64newData=loadData("someNewInstances")labels,scores:=forest.Predict(newData)}

Contributing

Contributions are greatly appreciated. The project follows the typicalGitHub pull request modelfor contribution.

License

The sources are release under a BSD 3-Clause License. The full terms of thatlicense can be found inLICENSE file of this repository.

About

Isolation forest implementation in Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp