Пример #1
0
def trace_it(clf, X, y, title) :
    """
    Cette fonction trace les frontieres de decision pour le classieur clf et les donnees labelisees superposees
    """
    frontiere(lambda xx: clf.predict(xx), X)
    for i, c in zip(xrange(3), "byr"):
        idx = np.where(y == i)
        plt.scatter(X[idx, 0], X[idx, 1], c=c, label=iris.target_names[i], cmap=plt.cm.Paired)
    plt.title(title)
    plt.show()
Пример #2
0
display_1 = [2, 2]
display_2 = [3, 1]
display_2bis = [3, 3]
display_2ter = [1.5, 2.5]
display_2quad = [1.5, 2]

values_proba1 = classi_ind_regr(display_1, X, y, k=3)[1]
values_proba2 = classi_ind_regr(display_2, X, y, k=3)[1]
values_proba2bis = classi_ind_regr(display_2bis, X, y, k=3)[1]
values_proba2ter = classi_ind_regr(display_2ter, X, y, k=3)[1]
values_proba2quad = classi_ind_regr(display_2quad, X, y, k=3)[1]

resolution_param = 50  # 500 for nice plotting, 50 for fast version

frontiere(lambda xx: classi_ind_regr(xx, X, y, k=3)[0], X,
          step=resolution_param)

color_text = '#ff8101'
plt.annotate(r'' + '(%.2f' % values_proba1[0] + ', %.2f' % values_proba1[1] +
             ', %.2f)' % values_proba1[2],
             xy=(display_1[0], display_1[1]), xycoords='data',
             color =color_text, xytext=(-15, -99), textcoords='offset points',
             fontsize=12, arrowprops=dict(arrowstyle="->",
             connectionstyle="arc3,rad=.2", color=color_text))

plt.plot(display_1[0], display_1[1], 'o', color=color_text, markersize=12)

plt.annotate(r'' + '(%.2f' % values_proba2[0] + ', %.2f' % values_proba2[1] +
             ', %.2f)' % values_proba2[2], xy=(display_2[0], display_2[1]),
             xycoords='data', color =color_text, xytext=(-150, -40),
             textcoords='offset points', fontsize=12,
Пример #3
0
display_1 = [2, 2]
display_2 = [3, 1]
display_3 = [2.5, 2.5]

values_proba_qda_1 = np.exp(clf.predict_log_proba(display_1))[0]
values_proba_qda_2 = np.exp(clf.predict_log_proba(display_2))[0]
values_proba_qda_3 = np.exp(clf.predict_log_proba(display_3))[0]

fig3 = plt.figure()
plot_2d(X, y)

resolution_param = 500  # 500 for nice plotting, 50 for fast version
color_text = '#ff8101'

frontiere(lambda xx: clf.predict(xx), X, step=resolution_param)

plt.annotate(r'' + '(%.2f' % values_proba_qda_1[0] + ', %.2f'
             % values_proba_qda_1[1] + ', %.2f)' % values_proba_qda_1[2],
             xy=(display_1[0], display_1[1]), xycoords='data',
             color=color_text, xytext=(-150, +100), textcoords='offset points',
             fontsize=12, arrowprops=dict(arrowstyle="->",
             connectionstyle="arc3,rad=.2", color=color_text))

plt.plot(display_1[0], display_1[1], 'o', color=color_text, markersize=12)
plt.annotate(r'' + '(%.2f' % values_proba_qda_2[0] + ', %.2f'
             % values_proba_qda_2[1] + ', %.2f)' % values_proba_qda_2[2],
             xy=(display_2[0], display_2[1]), xycoords='data',
             color =color_text, xytext=(-150, -40), textcoords='offset points',
             fontsize=12, arrowprops=dict(arrowstyle="->",
             connectionstyle="arc3,rad=.2", color=color_text))