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 2: 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.linear_model import LogisticRegression
model = LogisticRegression(random_state =0).f it (X_train.values, y_train)
print coefficients and the intercept
print (model.coef_)
print(model.intercept_)
4 visualize support vectors and the boundaries
ax = plt.gca()
xlim = ax.get_xlim()
ylim = ax.get_ylim()
plt.xlabel('petal_length')
plt.ylabel('petal_width')
=np.1 inspace (xlim?[0],xlim?[1],30)
yy = np.linspace (ylim?[0],ylim?[1],30)
YY,xx=np.meshgrid(Yy,xx
xy= np.vstack ([XX.ravel (), YY.ravel()]).T
z= model.decision_function(xy.reshape(XX.shape) # get f(x), i.e., the decision function
# plot the decision boundary f(x)=0, as well as references f(x)=-1 and f(x)=1.
ax.contour , colors='k', levels=[-1,0,1], alpha=0.5, linestyles=['--','-','--'])
plt.show ()
[2.31381394,0.90900393]
]
a) Write the decision boundary formula, i.e.,f(x).
b) If a new species has been discovered with petal length of 2.5 and petal width of
0.75, what is the probability that this species belongs to setosa? (The classes are
ordered as [setosa, versicolor].)
 Problem 2: In the class example, we apply logistic regression to

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!