benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 4459699f-a013-5b34-8ce1-e5d1843d05d4

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.decomposition import PCA

def task_func(df):
    """
    Perform Principal Component Analysis (PCA) on the DataFrame and record the first two main components.
    
    Parameters:
    - df (DataFrame): The pandas DataFrame.
    
    Returns:
    - df_pca (DataFrame): The DataFrame with the first two principal components named 'PC1' and 'PC2' as columns.

    Requirements:
    - pandas
    - sklearn
    
    Example:
    >>> df = pd.DataFrame([[5.1, 3.5, 1.4], [4.9, 3.0, 1.4], [4.7, 3.2, 1.3]], columns = ['x', 'y', 'z'])
    >>> df_pca = task_func(df)
    >>> print(df_pca)
            PC1       PC2
    0  0.334781 -0.011992
    1 -0.187649 -0.142630
    2 -0.147132  0.154622
    """

instruct prompt

Perform Principal Component Analysis (PCA) on the DataFrame and record the first two main components.
The function should output with:
    df_pca (DataFrame): The DataFrame with the first two principal components named 'PC1' and 'PC2' as columns.
You should write self-contained code starting with:

Code

import pandas as pd
from sklearn.decomposition import PCA
def task_func(df):

code prompt

Code

import pandas as pd
from sklearn.decomposition import PCA
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