Skip to content
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

Zhur homework 8 #11

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions dota-baseline_lgxp.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dota-baseline_only_index.ipynb

Large diffs are not rendered by default.

1,176 changes: 1,126 additions & 50 deletions lecture_1_intro_knn/homework/KNN.ipynb

Large diffs are not rendered by default.

41 changes: 18 additions & 23 deletions lecture_1_intro_knn/homework/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ def binary_classification_metrics(y_pred, y_true):
# https://en.wikipedia.org/wiki/Precision_and_recall
# https://en.wikipedia.org/wiki/F1_score

"""
YOUR CODE IS HERE
"""
pass
tp = np.sum((y_pred == 1) & (y_true == 1))
tn = np.sum((y_pred == 0) & (y_true == 0))
fp = np.sum((y_pred == 1) & (y_true == 0))
fn = np.sum((y_pred == 0) & (y_true == 1))

precision = tp / (tp + fp) if (tp + fp) > 0 else 0
recall = tp / (tp + fn) if (tp + fn) > 0 else 0
f1 = 2 * precision * recall / (precision + recall) if (precision + recall) > 0 else 0
accuracy = (tp + tn) / (tp + tn + fp + fn)

return precision, recall, f1, accuracy


def multiclass_accuracy(y_pred, y_true):
Expand All @@ -31,11 +38,8 @@ def multiclass_accuracy(y_pred, y_true):
Returns:
accuracy - ratio of accurate predictions to total samples
"""
return np.mean(y_pred == y_true)

"""
YOUR CODE IS HERE
"""
pass


def r_squared(y_pred, y_true):
Expand All @@ -47,11 +51,10 @@ def r_squared(y_pred, y_true):
Returns:
r2 - r-squared value
"""

"""
YOUR CODE IS HERE
"""
pass
ss_res = np.sum((y_true - y_pred) ** 2)
ss_tot = np.sum((y_true - np.mean(y_true)) ** 2)
r2 = 1 - (ss_res / ss_tot)
return r2


def mse(y_pred, y_true):
Expand All @@ -63,11 +66,7 @@ def mse(y_pred, y_true):
Returns:
mse - mean squared error
"""

"""
YOUR CODE IS HERE
"""
pass
return np.mean((y_pred - y_true) ** 2)


def mae(y_pred, y_true):
Expand All @@ -79,9 +78,5 @@ def mae(y_pred, y_true):
Returns:
mae - mean absolut error
"""

"""
YOUR CODE IS HERE
"""
pass
return np.mean(np.abs(y_pred - y_true))

1,195 changes: 1,109 additions & 86 deletions lecture_2_linmodels_GD/homework/Linear_models.ipynb

Large diffs are not rendered by default.

Loading