benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 60050d7d-9c56-58d3-a045-a3cd952bbd1a

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
from statsmodels.formula.api import ols


def task_func(mu, sigma, seed=0, num_samples=1000, num_bins=30):
    '''
    Create a histogram of a normal distribution with a given mean and standard deviation, and overlay the 
    probability density function (PDF) of the normal distribution on the histogram. Additionally, overlay a 
    second order polynomial function on the histogram fitted bin-wise using ordinary least squares (OLS) 
    regression. The random seed is set for reproducibility. The color of the PDF line is red, and the color of the OLS line is green.
    
    Parameters:
    - mu (float): The mean of the distribution.
    - sigma (float): The standard deviation of the distribution.
    - seed (int, Optional): The random seed for reproducibility. Defaults to 0.
    - num_samples (int, Optional): The number of samples to generate from the distribution. Defaults to 1000.
    - num_bins (int, Optional): The number of bins to use in the histogram. Defaults to 30.
    
    Returns:
    - matplotlib.axes.Axes: The Axes object with the histogram and overlaid PDF.
    
    Requirements:
    - numpy
    - matplotlib.pyplot
    - statsmodels.formula.api
    
    Example:
    >>> ax = task_func(0, 1)
    >>> type(ax)
    <class 'matplotlib.axes._axes.Axes'>
    '''

instruct prompt

Create a histogram of a normal distribution with a given mean and standard deviation, and overlay the probability density function (PDF) of the normal distribution on the histogram. Additionally, overlay a second order polynomial function on the histogram fitted bin-wise using ordinary least squares (OLS) regression. The random seed is set for reproducibility. The color of the PDF line is red, and the color of the OLS line is green.
The function should output with:
    matplotlib.axes.Axes: The Axes object with the histogram and overlaid PDF.
You should write self-contained code starting with:

Code

import numpy as np
import matplotlib.pyplot as plt
from statsmodels.formula.api import ols
def task_func(mu, sigma, seed=0, num_samples=1000, num_bins=30):

code prompt

Code

import numpy as np
import matplotlib.pyplot as plt
from statsmodels.formula.api import ols
def task_func(mu, sigma, seed=0, num_samples=1000, num_bins=30):

entry point

task_func

libs

  • numpy
  • matplotlib
  • statsmodels

Discussion

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

Official source

initial import