當前位置: 首頁>>代碼示例>>Python>>正文


Python OneClassSVM.predict_proba方法代碼示例

本文整理匯總了Python中sklearn.svm.OneClassSVM.predict_proba方法的典型用法代碼示例。如果您正苦於以下問題:Python OneClassSVM.predict_proba方法的具體用法?Python OneClassSVM.predict_proba怎麽用?Python OneClassSVM.predict_proba使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sklearn.svm.OneClassSVM的用法示例。


在下文中一共展示了OneClassSVM.predict_proba方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: embed_dat_matrix_two_dimensions

# 需要導入模塊: from sklearn.svm import OneClassSVM [as 別名]
# 或者: from sklearn.svm.OneClassSVM import predict_proba [as 別名]
def embed_dat_matrix_two_dimensions(low_dimension_data_matrix,
                                    y=None,
                                    labels=None,
                                    density_colormap='Blues',
                                    instance_colormap='YlOrRd'):
    from sklearn.preprocessing import scale
    low_dimension_data_matrix = scale(low_dimension_data_matrix)
    # make mesh
    x_min, x_max = low_dimension_data_matrix[:, 0].min(), low_dimension_data_matrix[:, 0].max()
    y_min, y_max = low_dimension_data_matrix[:, 1].min(), low_dimension_data_matrix[:, 1].max()
    step_num = 50
    h = min((x_max - x_min) / step_num, (y_max - y_min) / step_num)  # step size in the mesh
    b = h * 10  # border size
    x_min, x_max = low_dimension_data_matrix[:, 0].min() - b, low_dimension_data_matrix[:, 0].max() + b
    y_min, y_max = low_dimension_data_matrix[:, 1].min() - b, low_dimension_data_matrix[:, 1].max() + b
    xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))

    # induce a one class model to estimate densities
    from sklearn.svm import OneClassSVM
    gamma = max(x_max - x_min, y_max - y_min)
    clf = OneClassSVM(gamma=gamma, nu=0.1)
    clf.fit(low_dimension_data_matrix)

    # Plot the decision boundary. For that, we will assign a color to each
    # point in the mesh [x_min, m_max] . [y_min, y_max].
    if hasattr(clf, "decision_function"):
        score_matrix = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])
    else:
        score_matrix = clf.predict_proba(np.c_[xx.ravel(), yy.ravel()])[:, 1]
    # Put the result into a color plot
    levels = np.linspace(min(score_matrix), max(score_matrix), 40)
    score_matrix = score_matrix.reshape(xx.shape)

    if y is None:
        y = 'white'

    plt.contourf(xx, yy, score_matrix, cmap=plt.get_cmap(density_colormap), alpha=0.9, levels=levels)
    plt.scatter(low_dimension_data_matrix[:, 0], low_dimension_data_matrix[:, 1],
                alpha=.5,
                s=70,
                edgecolors='gray',
                c=y,
                cmap=plt.get_cmap(instance_colormap))
    # labels
    if labels is not None:
        for id in range(low_dimension_data_matrix.shape[0]):
            label = labels[id]
            x = low_dimension_data_matrix[id, 0]
            y = low_dimension_data_matrix[id, 1]
            plt.annotate(label, xy=(x, y), xytext=(0, 0), textcoords='offset points')
開發者ID:gianlucacorrado,項目名稱:EDeN,代碼行數:52,代碼來源:embedding.py

示例2: transform_cat_with_tfidf

# 需要導入模塊: from sklearn.svm import OneClassSVM [as 別名]
# 或者: from sklearn.svm.OneClassSVM import predict_proba [as 別名]
	### Record bidder_ids for output submission
	bidder_ids = test_data[:, 0]
     
	### Convert features to float
	# features = features.astype(np.float)
	
	### Transform sparse matrix
	# features = transform_cat_with_tfidf (features, tfidf)
	
	### SelectKBest
	if select_k == True:
		features = selector.transform(features)


	### Predict output
	predict_prob = clf.predict_proba(features)

	# open in byte mode for older Python2.7
	# csv_out = csv.writer(open('D:/Kaggle/HumanVRobot/results/temp.csv', 'wb'))

	### Dump to csv
	# csv_out = csv.writer(open('D:/Kaggle/HumanVRobot/results/gbc_tune_59_to_40feat_ccv5.csv', 'w', newline = ''))
	# csv_out = csv.writer(open('D:/Kaggle/HumanVRobot/results/rfc_tune_59_to_40feat_ccv5.csv', 'w', newline = ''))
	# csv_out = csv.writer(open('D:/Kaggle/HumanVRobot/results/etc_gini_tune_59feat_ccv5.csv', 'w', newline = ''))
	csv_out = csv.writer(open('D:/Kaggle/HumanVRobot/results/temp.csv', 'w', newline = ''))
	# csv_out = csv.writer(open('D:/Kaggle/HumanVRobot/results/bagging_tune_59feat_cv5.csv', 'w', newline = ''))

	data = []
	data.append(['bidder_id', 'prediction'])
	for idx in range(len(predict_prob)):
		data.append([bidder_ids[idx], predict_prob[idx, 1]]) 					# We want to only dump class probabilities for bot
開發者ID:sathishrvijay,項目名稱:Kaggle-HumanVsRobot,代碼行數:33,代碼來源:classifier_exp.py


注:本文中的sklearn.svm.OneClassSVM.predict_proba方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。