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())
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