-
Notifications
You must be signed in to change notification settings - Fork 185
Build a Simple ETL Pipeline (MLOps) #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e2a9a9
Added Two New Questions(Probability)
Jeet009 1c96b23
Added new ML Ops questions
Jeet009 784bf19
added new question on mlops
Jeet009 495a310
etl pipeline question
Jeet009 cfc2130
Final commit
Jeet009 5c8919f
fixed test cases
Jeet009 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
added new question on mlops
- Loading branch information
commit 784bf192bb1a659c0b5ec023b721f0ee40059c64
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| "id": "185", | ||
| "title": "Basic Data Drift Check: Mean and Variance Thresholds", | ||
| "difficulty": "easy", | ||
| "category": "MLOps", | ||
| "video": "", | ||
| "likes": "0", | ||
| "dislikes": "0", | ||
| "contributor": [ | ||
| { | ||
| "profile_link": "https://github.com/Jeet009", | ||
| "name": "Jeet Mukherjee" | ||
| } | ||
| ], | ||
| "description": "## Problem\n\nImplement a basic data drift check comparing two numeric datasets (reference vs. current).\n\nWrite a function `check_drift(ref, cur, mean_threshold, var_threshold)` that:\n\n- Accepts two lists of numbers `ref` and `cur`.\n- Computes the absolute difference in means and variances.\n- Returns a tuple `(mean_drift, var_drift)` where each element is a boolean indicating whether drift exceeds the corresponding threshold:\n\t- `mean_drift = abs(mean(ref) - mean(cur)) > mean_threshold`\n\t- `var_drift = abs(var(ref) - var(cur)) > var_threshold`\n\nAssume population variance (divide by N). Handle empty inputs by returning `(False, False)`.", | ||
| "learn_section": "## Solution Explanation\n\nWe compare two numeric samples (reference vs. current) using mean and variance with user-defined thresholds.\n\n### Definitions\n- Mean: \\( \\mu = \\frac{1}{N}\\sum_i x_i \\)\n- Population variance: \\( \\sigma^2 = \\frac{1}{N}\\sum_i (x_i - \\mu)^2 \\)\n\n### Drift rules\n- Mean drift if \\(|\\mu_{ref} - \\mu_{cur}| > \\tau_{mean}\\)\n- Variance drift if \\(|\\sigma^2_{ref} - \\sigma^2_{cur}| > \\tau_{var}\\)\n\n### Edge cases\n- If either sample is empty, return `(False, False)` to avoid false alarms.\n- Population vs. sample variance: we use population here to match many monitoring setups. Either is fine if used consistently.\n\n### Complexity\n- O(N + M) to compute stats; O(1) extra space.", | ||
| "starter_code": "from typing import List, Tuple\n\n\ndef check_drift(ref: List[float], cur: List[float], mean_threshold: float, var_threshold: float) -> Tuple[bool, bool]:\n\t\"\"\"Return (mean_drift, var_drift) comparing ref vs cur with given thresholds.\n\n\tUse population variance.\n\t\"\"\"\n\t# TODO: handle empty inputs; compute means and variances; compare with thresholds\n\traise NotImplementedError", | ||
| "solution": "from typing import List, Tuple\n\n\ndef _mean(xs: List[float]) -> float:\n\treturn sum(xs) / len(xs) if xs else 0.0\n\n\ndef _var(xs: List[float]) -> float:\n\tif not xs:\n\t\treturn 0.0\n\tm = _mean(xs)\n\treturn sum((x - m) * (x - m) for x in xs) / len(xs)\n\n\ndef check_drift(ref: List[float], cur: List[float], mean_threshold: float, var_threshold: float) -> Tuple[bool, bool]:\n\tif not ref or not cur:\n\t\treturn (False, False)\n\tmean_ref = _mean(ref)\n\tmean_cur = _mean(cur)\n\tvar_ref = _var(ref)\n\tvar_cur = _var(cur)\n\tmean_drift = abs(mean_ref - mean_cur) > mean_threshold\n\tvar_drift = abs(var_ref - var_cur) > var_threshold\n\treturn (mean_drift, var_drift)", | ||
| "example": { | ||
| "input": "check_drift([1, 2, 3], [1.1, 2.2, 3.3], 0.05, 0.1)", | ||
| "output": "(True, True)", | ||
| "reasoning": "Mean(ref)=2.0, Mean(cur)=2.2 → |Δ|=0.2>0.05. Var(ref)=2/3≈0.667; Var(cur)=1.21×0.667≈0.807 → |Δ|≈0.14>0.1." | ||
| }, | ||
| "test_cases": [ | ||
| { | ||
| "test": "from solution import check_drift; print(check_drift([1,2,3], [1.1,2.2,3.3], 0.05, 0.1))", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to import anything from solution, the test case could just be |
||
| "expected_output": "(True, True)" | ||
| }, | ||
| { | ||
| "test": "from solution import check_drift; print(check_drift([0,0,0], [0,0,0], 0.01, 0.01))", | ||
| "expected_output": "(False, False)" | ||
| }, | ||
| { | ||
| "test": "from solution import check_drift; print(check_drift([], [1,2,3], 0.01, 0.01))", | ||
| "expected_output": "(False, False)" | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| ## Problem | ||
|
|
||
| Implement a basic data drift check comparing two numeric datasets (reference vs. current). | ||
|
|
||
| Write a function `check_drift(ref, cur, mean_threshold, var_threshold)` that: | ||
|
|
||
| - Accepts two lists of numbers `ref` and `cur`. | ||
| - Computes the absolute difference in means and variances. | ||
| - Returns a tuple `(mean_drift, var_drift)` where each element is a boolean indicating whether drift exceeds the corresponding threshold: | ||
| - `mean_drift = abs(mean(ref) - mean(cur)) > mean_threshold` | ||
| - `var_drift = abs(var(ref) - var(cur)) > var_threshold` | ||
|
|
||
| Assume population variance (divide by N). Handle empty inputs by returning `(False, False)`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "input": "check_drift([1, 2, 3], [1.1, 2.2, 3.3], 0.05, 0.1)", | ||
| "output": "(True, True)", | ||
| "reasoning": "Mean(ref)=2.0, Mean(cur)=2.2 → |Δ|=0.2>0.05. Var(ref)=2/3≈0.667; Var(cur)=1.21×0.667≈0.807 → |Δ|≈0.14>0.1." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| ## Solution Explanation | ||
|
|
||
| We compare two numeric samples (reference vs. current) using mean and variance with user-defined thresholds. | ||
|
|
||
| ### Definitions | ||
| - Mean: \( \mu = \frac{1}{N}\sum_i x_i \) | ||
| - Population variance: \( \sigma^2 = \frac{1}{N}\sum_i (x_i - \mu)^2 \) | ||
|
|
||
| ### Drift rules | ||
| - Mean drift if \(|\mu_{ref} - \mu_{cur}| > \tau_{mean}\) | ||
| - Variance drift if \(|\sigma^2_{ref} - \sigma^2_{cur}| > \tau_{var}\) | ||
|
|
||
| ### Edge cases | ||
| - If either sample is empty, return `(False, False)` to avoid false alarms. | ||
| - Population vs. sample variance: we use population here to match many monitoring setups. Either is fine if used consistently. | ||
|
|
||
| ### Complexity | ||
| - O(N + M) to compute stats; O(1) extra space. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "id": "185", | ||
| "title": "Basic Data Drift Check: Mean and Variance Thresholds", | ||
| "difficulty": "easy", | ||
| "category": "MLOps", | ||
| "video": "", | ||
| "likes": "0", | ||
| "dislikes": "0", | ||
| "contributor": [ | ||
| { "profile_link": "https://github.com/Jeet009", "name": "Jeet Mukherjee" } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from typing import List, Tuple | ||
|
|
||
|
|
||
| def _mean(xs: List[float]) -> float: | ||
| return sum(xs) / len(xs) if xs else 0.0 | ||
|
|
||
|
|
||
| def _var(xs: List[float]) -> float: | ||
| if not xs: | ||
| return 0.0 | ||
| m = _mean(xs) | ||
| return sum((x - m) * (x - m) for x in xs) / len(xs) | ||
|
|
||
|
|
||
| def check_drift(ref: List[float], cur: List[float], mean_threshold: float, var_threshold: float) -> Tuple[bool, bool]: | ||
| if not ref or not cur: | ||
| return (False, False) | ||
| mean_ref = _mean(ref) | ||
| mean_cur = _mean(cur) | ||
| var_ref = _var(ref) | ||
| var_cur = _var(cur) | ||
| mean_drift = abs(mean_ref - mean_cur) > mean_threshold | ||
| var_drift = abs(var_ref - var_cur) > var_threshold | ||
| return (mean_drift, var_drift) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from typing import List, Tuple | ||
|
|
||
|
|
||
| def check_drift(ref: List[float], cur: List[float], mean_threshold: float, var_threshold: float) -> Tuple[bool, bool]: | ||
| """Return (mean_drift, var_drift) comparing ref vs cur with given thresholds. | ||
|
|
||
| Use population variance. | ||
| """ | ||
| # TODO: handle empty inputs; compute means and variances; compare with thresholds | ||
| raise NotImplementedError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [ | ||
| { "test": "from solution import check_drift; print(check_drift([1,2,3], [1.1,2.2,3.3], 0.05, 0.1))", "expected_output": "(True, True)" }, | ||
| { "test": "from solution import check_drift; print(check_drift([0,0,0], [0,0,0], 0.01, 0.01))", "expected_output": "(False, False)" }, | ||
| { "test": "from solution import check_drift; print(check_drift([], [1,2,3], 0.01, 0.01))", "expected_output": "(False, False)" } | ||
| ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use $ and $$ for equations in the learn section