benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 1f93d4c2-229f-5de6-9fe0-61e2124d0d35

Problem

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

complete prompt

import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler


def task_func(records: np.ndarray, random_seed: int = 0) -> pd.DataFrame:
    """
    Randomly shuffle the given array's features, normalize its values, then convert to a DataFrame
    with shuffled feature names.

    Parameters:
    - records (np.ndarray): A 2D numpy array with each row as a record and each column as a feature.
    - random_seed (int, optional): Seed for random operations to ensure reproducibility.

    Returns:
    - pd.DataFrame: A pandas DataFrame containing the preprocessed data, with shuffled feature names.

    Raises:
    - ValueError: If records is not 2D.

    Requirements:
    - numpy
    - pandas
    - sklearn

    Notes:
    - This function normalizes data by subtracting the mean and scaling to unit variance.
    - Feature names are of format f{n}; for example, if the records have 5 features, feature
      names will be ["f1", "f2", "f3", "f4", "f5"] shuffled.

    Examples:
    >>> data = np.array([[1, 2, 3], [4, 5, 6]])
    >>> df = task_func(data, random_seed=42)
    >>> df.shape
    (2, 3)
    >>> df.columns
    Index(['f2', 'f3', 'f1'], dtype='object')
    >>> data = np.array([[-1, -2, -3, -4, -5], [0, 0, 0, 0, 0], [1, 2, 3, 4, 5]])
    >>> df = task_func(data, random_seed=24)
    >>> df
             f3        f1        f4        f5        f2
    0 -1.224745 -1.224745 -1.224745 -1.224745 -1.224745
    1  0.000000  0.000000  0.000000  0.000000  0.000000
    2  1.224745  1.224745  1.224745  1.224745  1.224745
    """

instruct prompt

Randomly shuffle the given array's features, normalize its values, then convert to a DataFrame with shuffled feature names.
Note that: Notes: This function normalizes data by subtracting the mean and scaling to unit variance. Feature names are of format f{n}; for example, if the records have 5 features, feature names will be ["f1", "f2", "f3", "f4", "f5"] shuffled.
The function should raise the exception for: ValueError: If records is not 2D.
The function should output with:
    pd.DataFrame: A pandas DataFrame containing the preprocessed data, with shuffled feature names.
You should write self-contained code starting with:

Code

import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
def task_func(records: np.ndarray, random_seed: int = 0) -> pd.DataFrame:

code prompt

Code

import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
def task_func(records: np.ndarray, random_seed: int = 0) -> pd.DataFrame:

entry point

task_func

libs

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