benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf cc3787d3-82cb-5a3b-8dcd-6ab8392f29e0

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
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report


def task_func(csv_file_path, target_column="target", test_size=0.2, n_estimators=100):
    """
    Processes a CSV file to train a Random Forest classifier and generates a formatted classification report.

    Parameters:
        csv_file_path (str): The path to the CSV file containing the data.
        target_column (str, optional): The name of the target variable column. Defaults to 'target'.
        test_size (float, optional): The proportion of the dataset to include in the test split. Defaults to 0.2.
        n_estimators (int, optional): The number of trees in the RandomForestClassifier. Defaults to 100.

    Returns:
        str: A formatted classification report. The report includes metrics such as precision, recall,
             f1-score for each class, as well as overall accuracy, macro average, and weighted average.

    Raises:
        ValueError: If the specified target_column is not found in the CSV file.

    Requirements:
        - pandas
        - sklearn

    Example:
    >>> report = task_func('/path/to/data.csv')
    >>> print(report)
    class 0        0.88       0.90       0.89          50
    class 1        0.89       0.87       0.88          48
    ...
    accuracy                           0.89         100
    macro avg       0.88       0.89       0.88         100
    weighted avg    0.89       0.89       0.89         100

    Note:
        The CSV file must have a column with the name specified by 'target_column', and it should be in a
        format readable by pandas.read_csv().
    """

instruct prompt

Processes a CSV file to train a Random Forest classifier and generates a formatted classification report.
Note that: The CSV file must have a column with the name specified by 'target_column', and it should be in a format readable by pandas.read_csv().
The function should raise the exception for: ValueError: If the specified target_column is not found in the CSV file.
The function should output with:
    str: A formatted classification report. The report includes metrics such as precision, recall,
    f1-score for each class, as well as overall accuracy, macro average, and weighted average.
You should write self-contained code starting with:

Code

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report
def task_func(csv_file_path, target_column="target", test_size=0.2, n_estimators=100):

code prompt

Code

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report
def task_func(csv_file_path, target_column="target", test_size=0.2, n_estimators=100):

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