Skip to content

Add weighted sampling function to weighted_yasin_buyuktepe.py#312

Open
Yasou13 wants to merge 1 commit intocanbula:masterfrom
Yasou13:patch-1
Open

Add weighted sampling function to weighted_yasin_buyuktepe.py#312
Yasou13 wants to merge 1 commit intocanbula:masterfrom
Yasou13:patch-1

Conversation

@Yasou13
Copy link
Contributor

@Yasou13 Yasou13 commented Mar 13, 2026

Describe your changes

Checklist

  • I have read the [CONTRIBUTING]
  • I have performed a self-review of my own code
  • I have run the code locally and it works as expected
  • I have commented my code, particularly in hard-to-understand areas

Screenshots (if appropriate)

Copilot AI review requested due to automatic review settings March 13, 2026 09:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a weighted_srs implementation for the Week02 weighted sampling homework.

Changes:

  • Introduces Week02/weighted_yasin_buyuktepe.py with a weighted_srs(data, n, weights, with_replacement=False) function.
  • Uses random.choices for sampling with replacement and random.sample for sampling without weights.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +4 to +6
if with_replacement: return random.choices(data, weights=weights, k=n) # sample with replacement
if not weights: return random.sample(data, n) # simple random sample without weights
return random.sample(data, n, counts=weights) # sample without replacement using weights as counts
Comment on lines +4 to +6
if with_replacement: return random.choices(data, weights=weights, k=n) # sample with replacement
if not weights: return random.sample(data, n) # simple random sample without weights
return random.sample(data, n, counts=weights) # sample without replacement using weights as counts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants