1.一直以来想写下机器学习训练AI算法的系列文章,作为较火的机器学习框架,也是日常项目开发中常用的一款工具,最近刚好挤时间梳理、总结下这块儿的知识体系。
2.熟悉、梳理、总结下scikit-learn框架OCSVM模型相关知识体系。
3.欢迎批评指正,欢迎互三,跪谢一键三连!
4.欢迎批评指正,欢迎互三,跪谢一键三连!
5.欢迎批评指正,欢迎互三,跪谢一键三连!
import sklearn
print( sklearn.__version__ )
# 0.19.2
!python --version
# Python 3.7.0
# 版本过高,部署至生产环境会产生N多问题,暂时不使用过高版本,实战总结为主

OC-SVM简要总结OC-SVM(One-Class Support Vector Machine)是一种无监督学习算法,支持向量机(Support Vector Machine,SVM)的变体,广泛应用于异常检测、离群点检测、网络安全、图像处理等领域。它可以帮助识别潜在的异常情况,对于保护系统的安全和发现异常行为具有重要的作用。margin)。异常检测:对于新数据点,通过计算其与超平面的距离,来判断该数据点是否为异常。距离较大的数据点更有可能是异常点。较小的nu值表示更少的异常点,较大的nu值表示更多的异常点。相似度核函数,例如线性核、高斯核等。计算复杂度较高数据分布不均匀或存在噪声的情况,效果可能不理想TSNE
t-SNE( t-distributed Stochastic Neighbor Embedding)是目前来说效果最好的数据降维与可视化方法,它能够将高维的数据降维到2维或3维,然后画成图的形式表现出来。目前来看,t-SNE是效果相对比较好,并且实现比较方便的方法。PCA 降维到 10 维左右,再使用 t-SNE 降维到 2 或 3 维空间进行可视化。如果在低维空间中具有可分性,则数据是可分的;如果在高维空间中不具有可分性,可能是数据不可分,也可能仅仅是因为不能投影到低维空间。t-SNE(TSNE)的原理是将数据点之间的相似度转换为概率。原始空间中的相似度由高斯联合概率表示,嵌入空间的相似度由“学生t分布”表示。scikit-learn中One-Class SVM常用方法及参数含义One-Class SVM中常用方法 | Methods defined here:
|
| decision_function(self, X)
| Signed distance to the separating hyperplane.
|
| Signed distance is positive for an inlier and negative for an outlier.
|
| Parameters
| ----------
| X : array-like, shape (n_samples, n_features)
|
| Returns
| -------
| X : array-like, shape (n_samples,)
| Returns the decision function of the samples.
|
| fit(self, X, y=None, sample_weight=None, **params)
| Detects the soft boundary of the set of samples X.
|
| Parameters
| ----------
| X : {
array-like, sparse matrix}, shape (n_samples, n_features)
| Set of samples, where n_samples is the number of samples and
| n_features is the number of features.
|
| sample_weight : array-like, shape (n_samples,)
| Per-sample weights. Rescale C per sample. Higher weights
| force the classifier to put more emphasis on these points.
|
| Returns
| -------
| self : object
| Returns self.
|
| Notes
| -----
| If X is not a C-ordered contiguous array it is copied.
|
| predict(self, X)
| Perform classification on samples in X.
|
| For an one-class model, +1 or -1 is returned.
|
| Parameters
| ----------
| X : {
array-like, sparse matrix}, shape (n_samples, n_features)
| For kernel="precomputed", the expected shape of X is
| [n_samples_test, n_samples_train]
|
| Returns
| -------
| y_pred : array, shape (n_samples,)
| Class labels for samples in X.
| Methods inherited from sklearn.base.BaseEstimator:
|
| __getstate__(self)
|
| __repr__(self)
| Return repr(self).
|
| __setstate__(self, state)
|
| get_params(self, deep=True)
| Get parameters for this estimator.
|
| Parameters
| ----------
| deep : boolean, optional
| If True, will return the parameters for this estimator and
| contained subobjects that are estimators.