CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Designing Machine Learning Workflows in Python

Afficher le cours

Instructions

  • Import the LocalOutlierFactor module as lof for convenience.
  • Create a list with thirty 1s followed by a 10, [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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# 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))
Modifier et exécuter le code