Question: Problem 2 : In the class example, we apply logistic regression to build a linear classifier to distinguish the iris species setosa ( in blue
Problem : In the class example, we apply logistic regression to build a linear classifier
to distinguish the iris species setosa in blue dots and versicolor in green dots as
shown below. We also report the coefficients and the intercept for the linear classifier.
from sklearn.linearmodel import LogisticRegression
model LogisticRegressionrandomstate it Xtrain.values, ytrain
print coefficients and the intercept
print modelcoef
printmodelintercept
visualize support vectors and the boundaries
ax pltgca
xlim axgetxlim
ylim axgetylim
pltxlabelpetallength'
pltylabelpetalwidth'
inspace
yy nplinspace
meshgrid
npvstack XXravel YYravelT
model.decisionfunctionreshapeXXshape # get ie the decision function
# plot the decision boundary as well as references and
axcontour colorsk levels alpha linestyles
pltshow
a Write the decision boundary formula, ie
b If a new species has been discovered with petal length of and petal width of
what is the probability that this species belongs to setosa? The classes are
ordered as setosa versicolor
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
