本文整理汇总了Python中Messages.calculate_probs_message方法的典型用法代码示例。如果您正苦于以下问题:Python Messages.calculate_probs_message方法的具体用法?Python Messages.calculate_probs_message怎么用?Python Messages.calculate_probs_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Messages
的用法示例。
在下文中一共展示了Messages.calculate_probs_message方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cv_predict
# 需要导入模块: import Messages [as 别名]
# 或者: from Messages import calculate_probs_message [as 别名]
def cv_predict(X, y, clf_class, **kwargs):
# Construct a kfolds object
kf = KFold(len(y), n_folds=10, shuffle=True)
y_prob = np.zeros((len(y), 2))
# Iterate through folds
for train_index, test_index in kf:
X_train, X_test = X[train_index], X[test_index]
y_train = y[train_index]
# Initialize a classifier with key word arguments
clf = clf_class(**kwargs)
clf.fit(X_train, y_train)
y_prob[test_index] = clf.predict_proba(X_test)
return y_prob, clf
msg.print_line()
msg.calculate_probs_message()
pred_prob, clf = cv_predict(X, y, KNN, n_neighbors=k)
pred_churn = pred_prob[:, 1]
joblib.dump(clf, 'D:\SLIIT\SoftwareIndustry\knn_model.pkl', compress=1)
# Number of times a predicted probability is assigned to an observation
counts = pandas.value_counts(np.ndarray.round(pred_churn, 3))
counts = pandas.concat([counts], axis=1).reset_index()
counts.columns = ['pred_prob', 'count']
print(counts)
df1 = pandas.DataFrame(counts).sort_values(by='pred_prob')
counts_list = df1.values.tolist()