Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Week02/weighted_kayraemre_karaosmanoglu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import random
def weighted_srs(data, n, weights, with_replacement=False):
w = weights if weights else [1]*len(data)
if with_replacement or weights:
return random.choices(data, weights=w, k=n)
res, d_c = [], list(data)
for _ in range(n): res.append(d_c.pop(random.randrange(len(d_c))))
return res

6 changes: 6 additions & 0 deletions Week03/shifted_kayraemre_karaosmanoglu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import statistics

def shifted(data):
mean = statistics.mean(data)
median = statistics.median(data)
return abs(mean - median) / abs(mean) * 100 if mean != 0 else 0
6 changes: 6 additions & 0 deletions weighted_kayraemre_karaosmanoglu,py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import random

def weighted_srs(data, n, weights, with_replacement=False):
if with_replacement: return random.choices(data, weights=weights, k=n)
if not weights: return random.sample(data, n)
return random.sample(data, n, counts=weights)
Loading