Solving Algorithmic Problems in Python with Pytest (2019)
1–10 of 45 posts
Re: Solving Algorithmic Problems in Python with Pytest (2019)
#2Re: Solving Algorithmic Problems in Python with Pytest (2019)
#3Re: Solving Algorithmic Problems in Python with Pytest (2019)
#4Re: Solving Algorithmic Problems in Python with Pytest (2019)
#5I see the point of pytest and the greatness of it. I like pytest but I like minimalism more. I dont find it a good showcase here: couldn't you have kept only the asserts and just run the script?
(There’s the option to get that behaviour in pytest as well with a parameter. Also, pytest may run the tests in parallel, which may speed up the results)
Re: Solving Algorithmic Problems in Python with Pytest (2019)
#6Test driven development is just such a good habit to get into. You trade just a little bit of ramp-up speed at the beginning of an implementation for a massive reduction in cognitive overhead.
You write the test for your non-existent model, then write the model and try to train the model to 'pass' the test? Do you also train it on the test case or on other data only?
Re: Solving Algorithmic Problems in Python with Pytest (2019)
#7(Also, it’s part of the standard library.)
Re: Solving Algorithmic Problems in Python with Pytest (2019)
#8 if i > 0 and (minimum == 0 or i Re: Solving Algorithmic Problems in Python with Pytest (2019)
#9Write a function biasedcoin(n,p) that takes the number of coin flips, n, and the probability of heads, p. It flips a biased coin n times, and returns the ratio of number of heads/number of tails. p is guaranteed to have two significant numbers eg. p = 0.60 or p = 0.74. You should use the random.randrange function to generate random numbers.
Example implementation
def biasedcoin(n,p):
import randrange from random
heads = tails = 0
for i in range(n):
if randrange(100) Re: Solving Algorithmic Problems in Python with Pytest (2019)
#10Test driven development is just such a good habit to get into. You trade just a little bit of ramp-up speed at the beginning of an implementation for a massive reduction in cognitive overhead.
I'd love to see how test driven development looks like for ML systems. You write the test for your non-existent model, then write the model and try to train the model to 'pass' the test? Do you also train it on the test case or on other data only?
Test that this ETL function expects a DataFrame with a given schema and returns one with a different (but also known) schema, even with all these edge cases in the filters and group-bys.
Test that the "train_classifier" method/function rejects negative penalisation parameters, returns an object of type X (a trained sklearn object say, or dictionary of weights that can be deserialised), fails loudly if you don't have enough samples from category Y etc.
Test that the predict method returns a probability as a float, a predicted class as an int, a DataFrame with metadata and headers, etc etc.