Logisticregression
Logisticregression
[1]: # Let's load and inspect the dataset to understand its structure and see if any␣
↪cleanup is needed.
import pandas as pd
data = pd.read_csv('/content/Iris.csv')
1
test_set_size = int(len(X) * test_size)
test_indices = indices[:test_set_size]
train_indices = indices[test_set_size:]
return X.iloc[train_indices], X.iloc[test_indices], y.iloc[train_indices],␣
↪y.iloc[test_indices]
# Gradient descent
for _ in range(self.num_iterations):
# Linear model
linear_model = np.dot(X, self.weights) + self.bias
# Apply sigmoid function
y_predicted = self.sigmoid(linear_model)
# Compute gradients
dw = (1 / n_samples) * np.dot(X.T, (y_predicted - y))
db = (1 / n_samples) * np.sum(y_predicted - y)
2
return [1 if i > 0.5 else 0 for i in y_predicted]
# Make predictions
y_pred = model.predict(X_test.values)
↪'Iris-versicolor', 2: 'Iris-virginica'})
3
recall = TP / (TP + FN) if (TP + FN) > 0 else 0
f1_score = 2 * (precision * recall) / (precision + recall) if (precision +␣
↪recall) > 0 else 0
Accuracy: 30.00%
Precision: 47.37
Recall: 100.00
F1 Score: 64.29