benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf c19fe153-c621-52aa-a788-64e1ef828bb1

Problem

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

complete prompt

import matplotlib.pyplot as plt
from sklearn.cluster import KMeans


def task_func(myList, n_clusters):
    """
    Cluster a list of 2D points using KMeans and visualize the clusters.

    Note: This function raises ValueError if it encounters invalid inputs.
    KMeans is performed with random_state = 42 and n_init = 10. Scatterplot
    uses red 'x' markers for cluster centers.

    Parameters:
    - myList (list): List of 2D points.
    - n_clusters (int): Number of clusters to form.

    Returns:
    - matplotlib.axes._axes.Axes: Axes object with the plotted clusters.

    Requirements:
    - matplotlib.pyplot
    - sklearn.cluster.KMeans

    Example:
    >>> myList = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
    >>> ax = task_func(myList, 2)
    >>> type(ax)
    <class 'matplotlib.axes._axes.Axes'>
    >>> ax.get_xticklabels()
    [Text(0.0, 0, '0'), Text(1.0, 0, '1'), Text(2.0, 0, '2'), Text(3.0, 0, '3'), Text(4.0, 0, '4'), Text(5.0, 0, '5'), Text(6.0, 0, '6'), Text(7.0, 0, '7'), Text(8.0, 0, '8'), Text(9.0, 0, '9'), Text(10.0, 0, '10')]
    """

instruct prompt

Cluster a list of 2D points using KMeans and visualize the clusters.
Note that: This function raises ValueError if it encounters invalid inputs. KMeans is performed with random_state = 42 and n_init = 10. Scatterplot uses red 'x' markers for cluster centers.
The function should output with:
    matplotlib.axes._axes.Axes: Axes object with the plotted clusters.
You should write self-contained code starting with:

Code

import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
def task_func(myList, n_clusters):

code prompt

Code

import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
def task_func(myList, n_clusters):

entry point

task_func

libs

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