Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started