当前位置: 首页>>代码示例>>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;未经允许,请勿转载。