benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 6defc411-efb7-5945-999a-a22121f6c4f4

Problem

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

complete prompt

import heapq
from sklearn.linear_model import LinearRegression

def task_func(df, feature, target, n=10):
    """
    Fit a simple linear regression model to two columns of a DataFrame 
    specified by feature and target. 
    return the indices of the n largest residuals as well as the linear 
    regression model.
    
    Parameters:
    df (pandas.DataFrame): A DataFrame with at least two numerical columns named 'col1' and 'col2'.
    feature (str): The DataFrame column used as feature.
    target (str): The DataFrame column used as target.
    n (int, optional): Number of largest residuals to return. Default is 10.
    
    Returns:
    list[int]: Indices of the n largest residuals.
    LinearRegression: The LinearRegression model.
    
    Raises:
    ValueError: If specified columns are not in the provided DataFrame.

    Requirements:
    - heapq
    - sklearn.linear_model
    
    Example:
    >>> df = pd.DataFrame({
    ...     'col1': [99, 86, 90, 70, 86, 95, 56, 98, 80, 81],
    ...     'col2': [21, 11, 21, 1, 26, 40, 4, 50, 34, 37]
    ... })
    >>> indices, model = task_func(df, 'col1', 'col2', n=5)
    >>> print(indices)
    [0, 1, 9, 7, 8]
    >>> print(model)
    LinearRegression()

    >>> df = pd.DataFrame({
    ...     'a': [1, 2, 3, 4, 5],
    ...     'b': [1, 2, 3, 4, 5]
    ... })
    >>> indices, model = task_func(df, 'a', 'b', n=3)
    >>> print(indices)
    [0, 1, 2]
    >>> print(model)
    LinearRegression()
    """

instruct prompt

Fit a simple linear regression model to two columns of a DataFrame specified by feature and target. return the indices of the n largest residuals as well as the linear regression model. >>> df = pd.DataFrame({ ...     'a': [1, 2, 3, 4, 5], ...     'b': [1, 2, 3, 4, 5] ... }) >>> indices, model = task_func(df, 'a', 'b', n=3) >>> print(indices) [0, 1, 2] >>> print(model) LinearRegression()
The function should raise the exception for: ValueError: If specified columns are not in the provided DataFrame.
The function should output with:
    list[int]: Indices of the n largest residuals.
    LinearRegression: The LinearRegression model.
You should write self-contained code starting with:

Code

import heapq
from sklearn.linear_model import LinearRegression
def task_func(df, feature, target, n=10):

code prompt

Code

import heapq
from sklearn.linear_model import LinearRegression
def task_func(df, feature, target, n=10):

entry point

task_func

libs

  • sklearn
  • heapq

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