benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 93278950-31c4-58f0-a481-670168a09c64

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import numpy as np
from sklearn.model_selection import cross_val_score
from sklearn.ensemble import RandomForestRegressor

def task_func(num_samples=100, n_estimators=100, random_seed=None, cv=5):
    '''
    Generate a dataset with five features sampled from the standard normal
    distribution and a target variable.
    The target value is created by computing the sum of the features and adding
    random numbers sampled from the standard normal distribution.
    Then cross-validate the dataset using a RandomForestRegressor model and
    return the mean cross-validation score.

    Parameters:
    - num_samples (int): Number of samples in the generated dataset. Default is 100.
    - n_estimators (int): Number of trees in RandomForestRegressor. Default is 100.
    - random_seed (int): Seed for random number generation. Default is None.
    - cv (int): Number of cross-validation folds. Default is 5.

    Returns:
    float: The mean cross-validation score.
    model: the trained model

    Raises:
    - ValueError: If num_samples / cv < 2

    Requirements:
    - numpy
    - sklearn.model_selection.cross_val_score
    - sklearn.ensemble.RandomForestRegressor

    Example:
    >>> res = task_func(random_seed=21, cv=3, n_estimators=90, num_samples=28)
    >>> print(res)
    (-0.7631373607354236, RandomForestRegressor(n_estimators=90, random_state=21))

    >>> results = task_func(random_seed=1)
    >>> print(results)
    (0.47332912782858, RandomForestRegressor(random_state=1))
    '''

instruct prompt

Generate a dataset with five features sampled from the standard normal distribution and a target variable. The target value is created by computing the sum of the features and adding random numbers sampled from the standard normal distribution. Then cross-validate the dataset using a RandomForestRegressor model and return the mean cross-validation score. >>> results = task_func(random_seed=1) >>> print(results) (0.47332912782858, RandomForestRegressor(random_state=1))
The function should raise the exception for: ValueError: If num_samples / cv < 2
The function should output with:
    float: The mean cross-validation score.
    model: the trained model
You should write self-contained code starting with:

Code

import numpy as np
from sklearn.model_selection import cross_val_score
from sklearn.ensemble import RandomForestRegressor
def task_func(num_samples=100, n_estimators=100, random_seed=None, cv=5):

code prompt

Code

import numpy as np
from sklearn.model_selection import cross_val_score
from sklearn.ensemble import RandomForestRegressor
def task_func(num_samples=100, n_estimators=100, random_seed=None, cv=5):

entry point

task_func

libs

  • numpy
  • sklearn

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