benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 1a0a42e0-b4a9-59b8-97b7-23b5cce35035

Problem

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

complete prompt

from sklearn.model_selection import train_test_split
from sklearn.metrics import precision_recall_curve
from tensorflow import keras
import matplotlib.pyplot as plt

def task_func(X, Y):
    """
    This function should:
    - Splits the input data into training (70%) and test (30%) sets.
    - Constructs a Keras Sequential model with one hidden dense layer and sigmoid activation.
      The input dimension is determined based on the first feature set of X.
    - Compiles the model using binary cross-entropy loss and SGD optimizer.
    - Fits the model to the training data in a non-verbose mode.
    - Plots the Precision-Recall curve for the model based on the test set data.

    Parameters:
    X (np.ndarray): Input data for the model. Must have at least one feature.
    Y (np.ndarray): Target labels for the model.

    Returns:
    - keras.models.Sequential: The trained Keras model.
    - matplotlib.axes._axes.Axes: The matplotlib Axes object for the Precision-Recall curve plot.
    
    Notes:
    - The plot's x-axis is labeled 'Recall', and the y-axis is labeled 'Precision'.
    - The title of the axes is set to 'Precision-Recall Curve'.
    - The axes object allows for further customization of the plot outside the function.

    Requirements:
    - tensorflow.keras
    - sklearn.model_selection.train_test_split
    - sklearn.metrics.precision_recall_curve
    - matplotlib.pyplot

    Examples:
    >>> X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
    >>> Y = np.array([[0], [1], [1], [0]])
    >>> model, ax = task_func(X, Y)
    >>> isinstance(model, Sequential)
    True
    >>> isinstance(ax, plt.Axes)
    True
    """

instruct prompt

This function should: - Splits the input data into training (70%) and test (30%) sets. - Constructs a Keras Sequential model with one hidden dense layer and sigmoid activation. The input dimension is determined based on the first feature set of X. - Compiles the model using binary cross-entropy loss and SGD optimizer. - Fits the model to the training data in a non-verbose mode. - Plots the Precision-Recall curve for the model based on the test set data.
Note that: Notes: The plot's x-axis is labeled 'Recall', and the y-axis is labeled 'Precision'. The title of the axes is set to 'Precision-Recall Curve'. The axes object allows for further customization of the plot outside the function.
The function should output with:
    keras.models.Sequential: The trained Keras model.
    matplotlib.axes._axes.Axes: The matplotlib Axes object for the Precision-Recall curve plot.
You should write self-contained code starting with:

Code

from sklearn.model_selection import train_test_split
from sklearn.metrics import precision_recall_curve
from tensorflow import keras
import matplotlib.pyplot as plt
def task_func(X, Y):

code prompt

Code

from sklearn.model_selection import train_test_split
from sklearn.metrics import precision_recall_curve
from tensorflow import keras
import matplotlib.pyplot as plt
def task_func(X, Y):

entry point

task_func

libs

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