Skip to content

Commit

Permalink
Fixed Issue csivitu#1
Browse files Browse the repository at this point in the history
  • Loading branch information
Atharva-mendhu committed Sep 29, 2024
1 parent 67e6490 commit 8a3079d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions neo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def __init__(self, learning_rate=0.01, epochs=50, batch_size=4, regularization_s

def fit(self, X, y):
n_samples, n_features = X.shape
self.weights = np.ones(n_features) # Error 1: Improper weight initialization
self.bias = np.zeros(n_features) # Error 2: Bias should be a scalar, not an array
self.weights = np.zeros(n_features)
self.bias = 0

for epoch in range(self.epochs):
indices = np.random.permutation(n_samples)
Expand All @@ -32,18 +32,18 @@ def fit(self, X, y):
db = (1 / len(X_batch)) * np.sum(y_predicted - y_batch)

if self.use_regularization:
dw += (self.regularization_strength / len(X_batch)) * self.weights # Error 3: Regularization applied incorrectly
dw += (self.regularization_strength / len(X_batch)) * self.weights

self.weights -= self.learning_rate * dw
self.bias -= self.learning_rate * db # Error 4: Incorrect bias update logic
self.bias -= self.learning_rate * db

if np.linalg.norm(dw) < 0.001:
break # Error 5: Inadequate stopping condition
if np.linalg.norm(dw) < 0.001:
break

def predict(self, X):
linear_model = np.dot(X, self.weights) + self.bias
y_predicted = sigmoid(linear_model)
y_class_pred = [1 if i >= 0.5 else 0 for i in y_predicted] # Error 6: Equality condition might lead to ambiguity
y_class_pred = [1 if i > 0.5 else 0 for i in y_predicted]
return np.array(y_class_pred)

X_train = np.array([[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]])
Expand All @@ -54,3 +54,4 @@ def predict(self, X):

predictions = model.predict(X_train)
print("Predicted classes:", predictions)

0 comments on commit 8a3079d

Please sign in to comment.