> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Local Outlier Factor Scala Object

## localOutlierFactor

Annotates a dataframe with a column containing the local outlier factor for each data record.
The dataframe should contain at least one GeometryType column. Rows must be unique. If one
geometry column is present it will be used automatically. If two are present, the one named
'geometry' will be used. If more than one are present and neither is named 'geometry', the
column name must be provided.

```scala theme={"system"}
def localOutlierFactor(
      dataframe: DataFrame,
      k: Int = 20,
      geometry: String = null,
      approximateKNN: Boolean = false,
      handleTies: Boolean = false,
      useSphere: Boolean = false,
      resultColumnName: String = "lof"): DataFrame =
```

### Parameters

<ParamField path="dataframe" type="DataFrame">
  dataframe containing the point geometries
</ParamField>

<ParamField path="k" type="Int">
  number of nearest neighbors that will be considered for the LOF calculation
</ParamField>

<ParamField path="geometry" type="String">
  name of the geometry column
</ParamField>

<ParamField path="approximateKNN" type="Boolean">
  whether to use approximate KNN. When false will use exact KNN join. Default is false
</ParamField>

<ParamField path="handleTies" type="Boolean">
  whether to handle ties in the k-distance calculation. Default is false
</ParamField>

<ParamField path="useSphere" type="Boolean">
  whether to use a cartesian or spheroidal distance calculation. Default is false
</ParamField>

<ParamField path="resultColumnName" type="String">
  the name of the column containing the lof for each row. Default is "lof"
</ParamField>

### Returns

A DataFrame containing the lof for each row

### Usage Examples

```scala theme={"system"}
import org.apache.sedona.stats.clustering.LocalOutlierFactor

// Example usage
val result = LocalOutlierFactor.localOutlierFactor(dataframe, epsilon, minPts)
```
