A simple outlier
When you first encounter a new type of algorithm, it is always a great idea to test it with a very simple example. So you decide to create a list containing thirty examples with the value 1.0 and just one example with value 10.0, which you expect should be flagged as an outlier. To make sure you use the algorithm correctly, you convert the list to a pandas dataframe, and feed it into the local outlier factor algorithm. pandas is available to you as pd.
Diese Übung ist Teil des Kurses
Designing Machine Learning Workflows in Python
Anleitung zur Übung
- Import the
LocalOutlierFactormodule asloffor convenience. - Create a list with thirty
1s followed by a10,[1.0, 1.0, ..., 1.0, 10.0]. - Cast the list to a data frame.
- Print the outlier scores produced by the local outlier factor algorithm.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Import the LocalOutlierFactor module
from sklearn.____ import ____ as lof
# Create the list [1.0, 1.0, ..., 1.0, 10.0] as explained
x = ____*30
x.____(10)
# Cast to a data frame
X = pd.____(x)
# Fit the local outlier factor and print the outlier scores
print(lof().____(X))