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

Update loss_func.py #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
56 changes: 56 additions & 0 deletions MLlib/loss_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,59 @@ def loss(X, Y, W):
y_pred = np.dot(X, W).T
L = np.sum(np.true_divide((np.abs(Y - y_pred) * 100), Y)) / X.shape[0]
return L




class RootMeanSquaredError():
"""
Calculate Root Mean Squared Error.
"""

@staticmethod
def loss(X, Y, W):
"""
Calculate loss by Root Mean Squared Error method.

PARAMETERS
==========

X:ndarray(dtype=float,ndim=1)
input vector
Y:ndarray(dtype=float)
output vector
W:ndarray(dtype=float)
Weights

RETURNS
=======

array of Root Mean Squared losses
"""
M = X.shape[0]
return np.sqrt(np.sum(np.square(np.dot(X, W) - Y)) / M)

@staticmethod
def derivative(X, Y, W):
"""
Calculate derivative for Root Mean Squared error method.

PARAMETERS
==========

X:ndarray(dtype=float,ndim=1)
input vector
Y:ndarray(dtype=float)
output vector
W:ndarray(dtype=float)
Weights

RETURNS
=======

array of derivates
"""
M = X.shape[0]
return np.dot(X.T, np.dot(X, W) - Y) / M