benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 23531552-ba0e-5c51-ab1e-d3ae1d65082c

Problem

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

complete prompt

import numpy as np
from sklearn.cluster import KMeans


def task_func(data, n_clusters=2, random_state=0):
    """
    Perform KMeans clustering on a list of data points with 2D coordinates and 
    return the cluster labels.

    The function takes a list of tuples, each containing an identifier and its 
    2D coordinates. It applies KMeans clustering to categorize the points.

    Parameters:
    data (list of tuples): Each tuple contains an identifier and its 2D coordinates (e.g., ('A', 1, 1)).
    n_clusters (int): The number of clusters to form. Defaults to 2.
    random_state (int): Determines random number generation for centroid
                        initialization. Use an int for reproducible output.
                        Defaults to 0.

    Returns:
    ndarray: A numpy array with the cluster labels for each item.

    Requirements:
    - numpy
    - sklearn.cluster.KMeans

    Example:
    >>> data = [('A', 1, 1), ('B', 2, 2), ('C', 300, 300), ('D', 400, 400)]
    >>> labels = task_func(data, n_clusters=2, random_state=42)
    >>> print(labels)
    [0 0 1 1]
    
    >>> data = [('T1', 1, 1), ('T2', 1, 1.1), ('T2', 1.1, 1), ('C1', 400, 400), ('C2', 401, 401), ('B1', 35, 35)]
    >>> labels = task_func(data, n_clusters=3, random_state=42)
    >>> print(labels)
    [0 0 0 1 1 2]
    """

instruct prompt

Perform KMeans clustering on a list of data points with 2D coordinates and return the cluster labels. The function takes a list of tuples, each containing an identifier and its 2D coordinates. It applies KMeans clustering to categorize the points. >>> data = [('T1', 1, 1), ('T2', 1, 1.1), ('T2', 1.1, 1), ('C1', 400, 400), ('C2', 401, 401), ('B1', 35, 35)] >>> labels = task_func(data, n_clusters=3, random_state=42) >>> print(labels) [0 0 0 1 1 2]
The function should output with:
    ndarray: A numpy array with the cluster labels for each item.
You should write self-contained code starting with:

Code

import numpy as np
from sklearn.cluster import KMeans
def task_func(data, n_clusters=2, random_state=0):

code prompt

Code

import numpy as np
from sklearn.cluster import KMeans
def task_func(data, n_clusters=2, random_state=0):

entry point

task_func

libs

  • 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