ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Designing Machine Learning Workflows in Python

Ver curso

Instrucciones del ejercicio

  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# 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))
Editar y ejecutar código