benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf f83c4190-8a56-5682-b889-27cb6245d18d
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import numpy as np
import matplotlib.pyplot as plt
# Constants
NUM_SAMPLES = 100
NUM_OUTLIERS = 5
def task_func(num_samples=NUM_SAMPLES, num_outliers=NUM_OUTLIERS):
"""
Generate a dataset comprising both normal data and artificially introduced outliers,
and plot a histogram of the combined data. The function detects outliers in the dataset
using the Interquartile Range (IQR) method, but it only considers the normally distributed
portion of the data for outlier detection. The outliers detected and the artificially
introduced outliers might not always coincide.
Parameters:
- num_samples (int): Number of samples to be drawn from a normal distribution. The default
value is 100. If set to zero or a negative number, no normal data will be generated,
and the dataset will only contain artificially introduced outliers.
- num_outliers (int): Number of outliers to be artificially introduced into the dataset.
These outliers are uniformly distributed between -10 and 10. The default value is 5.
If set to zero, no outliers will be artificially introduced.
Returns:
- data (numpy array): The combined dataset, including both normally distributed data and
the artificially introduced outliers.
- outliers_detected (numpy array): The outliers detected using the IQR method. This
detection is based solely on the normally distributed portion of the data.
- ax (matplotlib.axes._axes.Axes): The Axes object for the histogram
plot of the combined dataset.
Requirements:
- numpy
- matplotlib
Note:
- The artificially introduced outliers are not necessarily the same as the outliers
detected by the IQR method. The IQR method is applied only to the normally distributed
data, and thus some of the artificially introduced outliers may not be detected,
and some normal data points may be falsely identified as outliers.
Example:
>>> import numpy as np
>>> np.random.seed(0)
>>> data, outliers_detected, ax = task_func()
>>> print(outliers_detected)
[-9.61613603 -3.96850367 3.20347075]
"""
instruct prompt
Generate a dataset comprising both normal data and artificially introduced outliers, and plot a histogram of the combined data. The function detects outliers in the dataset using the Interquartile Range (IQR) method, but it only considers the normally distributed portion of the data for outlier detection. The outliers detected and the artificially introduced outliers might not always coincide.
Note that: The artificially introduced outliers are not necessarily the same as the outliers detected by the IQR method. The IQR method is applied only to the normally distributed data, and thus some of the artificially introduced outliers may not be detected, and some normal data points may be falsely identified as outliers.
The function should output with:
data (numpy array): The combined dataset, including both normally distributed data and
the artificially introduced outliers.
outliers_detected (numpy array): The outliers detected using the IQR method. This
detection is based solely on the normally distributed portion of the data.
ax (matplotlib.axes._axes.Axes): The Axes object for the histogram
plot of the combined dataset.
You should write self-contained code starting with:
Code
import numpy as np
import matplotlib.pyplot as plt
# Constants
NUM_SAMPLES = 100
NUM_OUTLIERS = 5
def task_func(num_samples=NUM_SAMPLES, num_outliers=NUM_OUTLIERS):
code prompt
Code
import numpy as np
import matplotlib.pyplot as plt
# Constants
NUM_SAMPLES = 100
NUM_OUTLIERS = 5
def task_func(num_samples=NUM_SAMPLES, num_outliers=NUM_OUTLIERS):
entry point
task_func
libs
- numpy
- matplotlib
Discussion
No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
See answer Answer published by the source
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Source and history
initial import