benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 5e59eb1e-2886-5454-a06f-c40e60e7d792

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.model_selection import train_test_split


def task_func(df):
    """
    Divide the given DataFrame into a training set and a test set (70%: 30% split), separate the "target" column and return the four resulting DataFrames.

    Parameters:
    - df (pd.DataFrame): pandas DataFrame that contains a column named 'target'.

    Returns:
    - tuple: A tuple containing four DataFrames: X_train, X_test, y_train, y_test.

    Requirements:
    - pandas
    - sklearn
    
    Example:
    >>> np.random.seed(42)  # Ensure reproducibility
    >>> df = pd.DataFrame(np.random.randint(0, 100, size=(100, 5)), columns=list('ABCDE'))  # Explicitly using np and pd
    >>> df['target'] = np.random.randint(0, 2, size=100)  # Adding 'target' column using np
    >>> X_train, X_test, y_train, y_test = task_func(df)
    >>> print(X_train.shape)  # Expected shape of training data
    (70, 5)
    """

instruct prompt

Divide the given DataFrame into a training set and a test set (70%: 30% split), separate the "target" column and return the four resulting DataFrames.
The function should output with:
    tuple: A tuple containing four DataFrames: X_train, X_test, y_train, y_test.
You should write self-contained code starting with:

Code

import pandas as pd
from sklearn.model_selection import train_test_split
def task_func(df):

code prompt

Code

import pandas as pd
from sklearn.model_selection import train_test_split
def task_func(df):

entry point

task_func

libs

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