benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 3098b704-c932-5dd5-b112-647ceb22c33e

Problem

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

complete prompt

import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression


def task_func(df, x_column, y_column):
    """
    Draws a scatter plot for the specified columns from a pandas DataFrame and fits a linear regression model to the data.

    Parameters:
    df (DataFrame): The input pandas DataFrame.
    x_column (str): The column name for the x-axis. Data contained in column must be numeric.
    y_column (str): The column name for the y-axis. Data contained in column must be numeric.

    Returns:
    matplotlib.axes._axes.Axes: The Axes object containing the scatter plot and the linear regression line.

    Requirements:
    - matplotlib
    - sklearn

    Notes:
    - After plotting the scatterplot, this function overlays the predicted regression line on top in red on the same Axes.

    Example:
    >>> import pandas as pd
    >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [2, 3, 4]})
    >>> ax = task_func(df, 'A', 'B')
    >>> type(ax)
    <class 'matplotlib.axes._axes.Axes'>
    """

instruct prompt

Draws a scatter plot for the specified columns from a pandas DataFrame and fits a linear regression model to the data.
Note that: Notes: After plotting the scatterplot, this function overlays the predicted regression line on top in red on the same Axes.
The function should output with:
    matplotlib.axes._axes.Axes: The Axes object containing the scatter plot and the linear regression line.
You should write self-contained code starting with:

Code

import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
def task_func(df, x_column, y_column):

code prompt

Code

import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
def task_func(df, x_column, y_column):

entry point

task_func

libs

  • matplotlib
  • 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