benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf fb379040-2acb-5abd-b341-9a7e2e48dd03

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.feature_selection import SelectKBest, f_classif
import seaborn as sns


def task_func(df1, df2):
    """Perform the feature selection with SelectKBest (k=2) and return a heatmap of the feature correlations.

    Parameters:
    - df1 (pd.DataFrame): The dataframe containing features.
    - df2 (pd.DataFrame): The dataframe containing the target variable. Must have an 'id' column corresponding to df1.

    Returns:
    - tuple: A tuple containing:
        - list: A list of the selected features.
        - Axes: A heatmap showing the correlation between the selected features.

    Requirements:
    - pandas
    - sklearn.feature_selection.SelectKBest
    - sklearn.feature_selection.f_classif
    - seaborn

    Example:
    >>> df1 = pd.DataFrame({'id': [1, 2, 3], 'feature1': [1.2, 3.4, 5.6], 'feature2': [2.3, 4.5, 6.7], 'feature3': [3.4, 5.6, 7.8]})
    >>> df2 = pd.DataFrame({'id': [1, 2, 3], 'target': [4.5, 6.7, 8.9]})
    >>> selected_features, heatmap = task_func(df1, df2)
    >>> heatmap
    <Axes: >
    >>> selected_features
    ['feature2', 'feature3']
    """

instruct prompt

Perform the feature selection with SelectKBest (k=2) and return a heatmap of the feature correlations.
The function should output with:
    tuple: A tuple containing:
    list: A list of the selected features.
    Axes: A heatmap showing the correlation between the selected features.
You should write self-contained code starting with:

Code

import pandas as pd
from sklearn.feature_selection import SelectKBest, f_classif
import seaborn as sns
def task_func(df1, df2):

code prompt

Code

import pandas as pd
from sklearn.feature_selection import SelectKBest, f_classif
import seaborn as sns
def task_func(df1, df2):

entry point

task_func

libs

  • pandas
  • sklearn
  • seaborn

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