benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 3b816f85-dedd-53ed-b1c0-60354b5fdc38

Problem

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

complete prompt

import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt


def task_func(data):
    """
    Normalizes a given dataset using MinMax scaling and calculates the average of each row. This average is then
    added as a new column 'Average' to the resulting DataFrame. The function also visualizes these averages in a plot.

    Parameters:
    data (numpy.array): A 2D array where each row represents a sample and each column a feature, with a
    shape of (n_samples, 8).

    Returns:
    DataFrame: A pandas DataFrame where data is normalized, with an additional column 'Average' representing the
    mean of each row.
    Axes: A matplotlib Axes object showing a bar subplot of the average values across the dataset.

    Requirements:
    - pandas
    - sklearn
    - matplotlib

    Example:
    >>> import numpy as np
    >>> data = np.array([[1, 2, 3, 4, 4, 3, 7, 1], [6, 2, 3, 4, 3, 4, 4, 1]])
    >>> df, ax = task_func(data)
    >>> print(df.round(2))
         A    B    C    D    E    F    G    H  Average
    0  0.0  0.0  0.0  0.0  1.0  0.0  1.0  0.0     0.25
    1  1.0  0.0  0.0  0.0  0.0  1.0  0.0  0.0     0.25
    """

instruct prompt

Normalizes a given dataset using MinMax scaling and calculates the average of each row. This average is then added as a new column 'Average' to the resulting DataFrame. The function also visualizes these averages in a plot.
The function should output with:
    DataFrame: A pandas DataFrame where data is normalized, with an additional column 'Average' representing the
    mean of each row.
    Axes: A matplotlib Axes object showing a bar subplot of the average values across the dataset.
You should write self-contained code starting with:

Code

import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
def task_func(data):

code prompt

Code

import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
def task_func(data):

entry point

task_func

libs

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