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
.
This exercise is part of the course
Designing Machine Learning Workflows in Python
Exercise instructions
- Import the
LocalOutlierFactor
module aslof
for convenience. - Create a list with thirty
1
s 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.
Hands-on interactive exercise
Have a go at this exercise by completing this sample 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))