Skip to content

Implement Logistic Regression Class for binary classification #5

Description

@dabasajay

Implement the LogisticRegression Class for binary classification problems.

LogisticRegression class should have these methods:

  • .fit(X,y) :- it takes in features(X) and targets(y) and trains the model.
  • .predict(X) :- it takes features(X) as input and outputs the predicted targets/labels(y)
  • .predict_proba(X) :- it takes features(X) as input and outputs the predicted probabilities of targets/labels(y)

Note:

  • .predict() can internally call .predict_proba() and then change probabilities to labels based on threshold(default to 0.5)

Test your model on IRIS dataset using 2 classes(instead of 3 classes of IRIS) available in the library and check how well it performs.
Example code

from learnemall.datasets import iris
from learnemall.linear import LogisticRegression
model = LogisticRegression()
X,y = iris.load_dataset()
# Take 2 classes only
X = X [ : , :-2]
y = (y!=0)*1
# train the model
model.fit(X,y)
# predict using model
y_pred = model.predict(X)
# Evaluate
print((y_pred == y).mean())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions