Scikit-learn:分类classification

时间:2021-11-20 10:02:46

http://blog.csdn.net/pipisorry/article/details/53034340

支持向量机SVM分类

svm分类有多种不同的算法。SVM是非常流行的机器学习算法,主要用于分类问题,如同逻辑回归问题,它可以使用一对多的方法进行多类别的分类。

svc

Implementation of Support Vector Machine classifier using libsvm: the kernel can be non-linear but its SMO algorithm does not scale to large number of samples as LinearSVC does. Furthermore SVC multi-class mode is implemented using one vs one scheme while LinearSVC uses one vs the rest. It is possible to implement one vs the rest with SVC by using the sklearn.multiclass.OneVsRestClassifier wrapper. Finally SVC can fit dense data without memory copy if the input is C-contiguous. Sparse data will still incur memory copy though.

class sklearn.svm.SVC(C=1.0, kernel='rbf', degree=3, gamma='auto', coef0=0.0, shrinking=True, probability=False, tol=0.001, cache_size=200, class_weight=None, verbose=False, max_iter=-1, decision_function_shape=None, random_state=None)

常用参数

probability : boolean, optional (default=False)

Whether to enable probability estimates. This must be enabled priorto calling fit, and will slow down that method.

常用属性

coef_ : array, shape = [n_class-1, n_features]

常用方法Methods

decision_function(X) Distance of the samples X to the separating hyperplane.
fit(X, y[, sample_weight]) Fit the SVM model according to the given training data.
get_params([deep]) Get parameters for this estimator.
predict(X) Perform classification on samples in X.
score(X, y[, sample_weight]) Returns the mean accuracy on the given test data and labels.
set_params(**params) Set the parameters of this estimator.

如果之前设置了参数probability=True,则可以使用输出概率函数

predict_proba

Compute probabilities of possible outcomes for samples in X.

The model need to have probability information computed at trainingtime: fit with attribute probability set to True.

Parameters:

X : array-like, shape (n_samples, n_features)

For kernel=”precomputed”, the expected shape of X is[n_samples_test, n_samples_train]

Returns:

T : array-like, shape (n_samples, n_classes)

Returns the probability of the sample for each class inthe model. The columns correspond to the classes in sortedorder, as they appear in the attribute classes_.

Notes The probability model is created using cross validation, sothe results can be slightly different than those obtained bypredict. Also, it will produce meaningless results on very smalldatasets.

使用示例

>>> import numpy as np
>>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])
>>> y = np.array([1, 1, 2, 2])
>>> from sklearn.svm import SVC
>>> clf = SVC()
>>> clf.fit(X, y)
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
    decision_function_shape=None, degree=3, gamma='auto', kernel='rbf',
    max_iter=-1, probability=False, random_state=None, shrinking=True,
    tol=0.001, verbose=False)
>>> print(clf.predict([[-0.8, -1]]))
[1]

[sklearn.svm.SVC]

LinearSVC

Implementation of Support Vector Machine classifier using the same library as this class (liblinear).
Scalable Linear Support Vector Machine for classification implemented using liblinear. Check the See also section of LinearSVC for more comparison element.

SVR

Support Vector Machine for Regression implemented using libsvm.

NuSVR

Support Vector Machine for regression implemented using libsvm using a parameter to control the number of support vectors.

LinearSVR

Scalable Linear Support Vector Machine for regression implemented using liblinear.

[sklearn.svm]

皮皮blog

from: http://blog.csdn.net/pipisorry/article/details/53034340

ref: