def check_proba_classif_convergence(X_train, y_train, mc):
lb = LabelBinarizer()
y_bin = lb.fit_transform(y_train)
le = LabelEncoder()
y_enc = le.fit_transform(y_train)
proba = mc.predict_proba(X_train)
labels = mc.predict(X_train)
assert_array_equal(proba, y_bin)
assert_array_equal(labels, lb.inverse_transform(y_bin))
# For points completely far away from the training data, this
# should converge to the empirical distribution of labels.
# X is scaled between to -1.0 and 1.0
X_inf = np.vstack((30.0 * np.ones(X_train.shape[1]),
-30.0 * np.ones(X_train.shape[1])))
inf_proba = mc.predict_proba(X_inf)
emp_proba = np.bincount(y_enc) / float(len(y_enc))
assert_array_almost_equal(inf_proba, [emp_proba, emp_proba])
评论列表
文章目录