Unverified Commit 645eb888 authored by Yang, Fangzhou's avatar Yang, Fangzhou Committed by GitHub
Browse files

Update README.md

parent 34e7a1e3
......@@ -101,6 +101,52 @@ println(s"Training and predicting time: ${(endTime - startTime) / 1000} seconds.
println(s"The model's auc: ${binaryMetrics.areaUnderROC()}")
```
*Python API*
```python
spark = SparkSession \
.builder.master("local[*]") \
.appName("IForestExample") \
.getOrCreate()
data = [(Vectors.dense([0.0, 0.0]),), (Vectors.dense([7.0, 9.0]),),
(Vectors.dense([9.0, 8.0]),), (Vectors.dense([8.0, 9.0]),)]
df = spark.createDataFrame(data, ["features"])
from pyspark_iforest.ml.iforest import *
iforest = IForest(contamination=0.3, maxDepth=2)
model = iforest.fit(df)
model.hasSummary
summary = model.summary
summary.numAnomalies
transformed = model.transform(df)
rows = transformed.collect()
temp_path = tempfile.mkdtemp()
iforest_path = temp_path + "/iforest"
iforest.save(iforest_path)
loaded_iforest = IForest.load(iforest_path)
model_path = temp_path + "/iforest_model"
model.save(model_path)
loaded_model = IForestModel.load(model_path)
loaded_model.hasSummary
loaded_model.transform(df).show()
```
## Benchmark
#### Environment
......
Markdown is supported
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