Commit 35f0dbe5 authored by fzyang's avatar fzyang
Browse files
parents 2a35c382 eaac3870
......@@ -117,35 +117,48 @@ df = spark.createDataFrame(data, ["features"])
from import *
# Init an IForest Object
iforest = IForest(contamination=0.3, maxDepth=2)
# Fit on a given data frame
model =
# Check if the model has summary or not, the newly trained model has the summary info
# Show model summary
summary = model.summary
# Show the number of anomalies
# Predict for a new data frame based on the fitted model
transformed = model.transform(df)
# Collect spark data frame into local df
rows = transformed.collect()
temp_path = tempfile.mkdtemp()
iforest_path = temp_path + "/iforest"
# Save the iforest estimator into the path
# Load iforest estimator from a path
loaded_iforest = IForest.load(iforest_path)
model_path = temp_path + "/iforest_model"
# Save the fitted model into the model path
# Load a fitted model from a model path
loaded_model = IForestModel.load(model_path)
# The loaded model has no summary info
# Use the loaded model to predict a new data frame
......@@ -231,7 +244,7 @@ Please cite spark-iforest in your publications if it helped your research. Here
author={Yang, Fangzhou and contributors},
author={Fangzhou Yang and contributors},
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment