I'm implementing an outlier's detection pipeline.

3 escenarios raised when I train the algorithm:

Should I first split the data before fitting my outlier's detection algorithm?

Should I fit only on train?

Should I split and then fit on train and test separately?

For illustrative purpose I'm going to use iris dataset 

A similar discussion is stated here in the case of scaling:

[Why do we need to re-use training parameters to transform test data?](https://sebastianraschka.com/faq/docs/scale-training-test.html)

```

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.ensemble import IsolationForest
from sklearn.neighbors import LocalOutlierFactor
from sklearn.svm import OneClassSVM
from sklearn.model_selection import train_test_split

from warnings import filterwarnings

filterwarnings('ignore')

X,y = load_iris(return_X_y= True)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .3, random_state = 123)

# Option 1

Iso_outliers = IsolationForest().fit(X_train)

Iso_outliers_train = Iso_outliers.predict(X_train)

Iso_outliers_test = Iso_outliers.predict(X_test)

# Option 2

Iso_outliers_train = IsolationForest().fit_predict(X_train)

Iso_outliers_test = IsolationForest().fit_predict(X_test)

# Option 3

Iso_outliers_X = IsolationForest().fit_predict(X)

```

1. Which of the 3 above options is the correct one and why?
2. Does it depend on the algorithm to be used or it would apply the same for any outlier's detection algorithm?