benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 9d02d105-331b-513d-b37a-253474fea2f4
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 StandardScaler
import matplotlib.pyplot as plt
# Constants
FEATURE_NAMES = ["Feature 1", "Feature 2", "Feature 3", "Feature 4", "Feature 5"]
def task_func(data_matrix):
"""
Standardize a 2D data matrix, calculate the mean value of each row and then visualize the distribution of the mean values with an histogram.
- Each row of the matrix represent a data point, its length is the same as that of FEATURE_NAMES.
- The plot title should be 'Distribution of Means'.
Parameters:
data_matrix (numpy.array): The 2D data matrix.
Returns:
tuple: A tuple containing:
- pandas.DataFrame: A DataFrame containing the standardized data and the mean of each row.
Its column names should be FEATURE_NAMES and 'Mean'.
- matplotlib.axes.Axes: The histogram plot of the distribution of means.
Requirements:
- pandas
- sklearn.preprocessing.StandardScaler
- matplotlib.pyplot
Example:
>>> import numpy as np
>>> data = np.array([[6, 8, 1, 3, 4], [-1, 0, 3, 5, 1]])
>>> df, ax = task_func(data)
>>> print(df)
Feature 1 Feature 2 Feature 3 Feature 4 Feature 5 Mean
0 1.0 1.0 -1.0 -1.0 1.0 0.2
1 -1.0 -1.0 1.0 1.0 -1.0 -0.2
"""
instruct prompt
Standardize a 2D data matrix, calculate the mean value of each row and then visualize the distribution of the mean values with an histogram. - Each row of the matrix represent a data point, its length is the same as that of FEATURE_NAMES. - The plot title should be 'Distribution of Means'.
The function should output with:
tuple: A tuple containing:
pandas.DataFrame: A DataFrame containing the standardized data and the mean of each row.
Its column names should be FEATURE_NAMES and 'Mean'.
matplotlib.axes.Axes: The histogram plot of the distribution of means.
You should write self-contained code starting with:
Code
import pandas as pd
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
# Constants
FEATURE_NAMES = ["Feature 1", "Feature 2", "Feature 3", "Feature 4", "Feature 5"]
def task_func(data_matrix):
code prompt
Code
import pandas as pd
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
# Constants
FEATURE_NAMES = ["Feature 1", "Feature 2", "Feature 3", "Feature 4", "Feature 5"]
def task_func(data_matrix):
entry point
task_func
libs
- pandas
- matplotlib
- sklearn
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
initial import