benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 43b82ea5-6e4b-5c9a-9257-dd661a33f3ba
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import re
from sklearn.cluster import KMeans
from sklearn.feature_extraction.text import CountVectorizer
def task_func(df):
"""
Analyzes articles by their titles for specific case-insensitive keywords ("how" or "what"), vectorizes the content using
CountVectorizer, and groups them into clusters using KMeans clustering. This function is intended for basic
content analysis and clustering to understand common themes or topics among articles asking questions starting
with "how" or "what".
Parameters:
df (pd.DataFrame): DataFrame containing article data with columns 'Title' for the article titles and 'Content' for
the article text.
Returns:
list: List of cluster labels for the filtered articles, indicating the cluster to which each article belongs.
Requirements:
- re
- sklearn
Example:
>>> import pandas as pd
>>> df_sample = pd.DataFrame({
... 'Title': ['How to code?', 'What is Python?', 'The art of programming', 'How to cook?', 'What is life?'],
... 'Content': ['This is a tutorial about coding...', 'Python is a programming language...',
... 'Programming is an art...', 'This is a cooking tutorial...', 'Life is complicated...']
... })
>>> task_func(df_sample)
[0, 1, 0, 1]
"""
instruct prompt
Analyzes articles by their titles for specific case-insensitive keywords ("how" or "what"), vectorizes the content using CountVectorizer, and groups them into clusters using KMeans clustering. This function is intended for basic content analysis and clustering to understand common themes or topics among articles asking questions starting with "how" or "what".
The function should output with:
list: List of cluster labels for the filtered articles, indicating the cluster to which each article belongs.
You should write self-contained code starting with:
Code
import re
from sklearn.cluster import KMeans
from sklearn.feature_extraction.text import CountVectorizer
def task_func(df):
code prompt
Code
import re
from sklearn.cluster import KMeans
from sklearn.feature_extraction.text import CountVectorizer
def task_func(df):
entry point
task_func
libs
- re
- sklearn
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
initial import