[更新ing]sklearn(十七):Density Estimation

利用“直方图”进行密度估计

利用直方图进行数据的密度估计:确定bin的大小后,计数各个bin中n_sample的个数作为数据密度。
直方图密度估计有一个明显的缺陷:即bin的大小不一样,可能得到的概率密度图存在较大差异。除此以外,利用直方图得到的概率密度图不连续。而kernel density estimation可以很好的解决上述问题。下图为“直方图”密度估计,和kernel density estimation图示,upper figure为直方图估计,左右两幅图的bin大小不一样,可以看出,不同的bin得出的密度图存在明显不同(一个双峰,一个单峰)。

从上图可以看出,kernel density estimation的密度图连续型更好。

kernel density estimation

可利用kernel density estimation计算数据中各个点的概率密度值,kernel density estimation在估计point密度时,并不假设data服从什么样的概率密度形式,而是根据公式:p=k/n/Vn来计算某点的密度值(k为在以point为中心, Vn的体积范围内点的个数;n为样本总量;Vn为体积(趋于0)),上述公式中k的计算可以衍生为用kernel来计算Vn体积内各个点的加权值,然后将k个加权值相加,作为最后的点数量的估计值。(Parzen窗方法 理论)

#neighbor-based approaches 
sklearn.neighbors.KernelDensity(bandwidth=1.0, algorithm=’auto’, kernel=’gaussian’, metric=’euclidean’, atol=0, rtol=0, breadth_first=True, leaf_size=40, metric_params=None)
#bandwidth:kernel的参数,bandwidth越大,bias越大,容易underfitting;bandwidth越小,variance越大,容易overfitting;
#algorithm:{kd_tree,ball_tree,auto}   需要搜索一定radius范围内point的近邻点,因此,需要用到kd_tree去构建搜索树
#breadth_first:用到相关算法,决定搜索策略
#kernel:[‘gaussian’|’tophat’|’epanechnikov’|’exponential’|’linear’|’cosine’] Default is ‘gaussian’.


核密度估计 Kernel Density Estimation(KDE)

GaussianMixture

sklearn.mixture.GaussianMixture(n_components=1, covariance_type=’full’, tol=0.001, reg_covar=1e-06, max_iter=100, n_init=1, init_params=’kmeans’, weights_init=None, means_init=None, precisions_init=None, random_state=None, warm_start=False, verbose=0, verbose_interval=10)
#n_components:Guassian distribution的个数
#covariance_type:{full:每个component有各自的covariance,tied:所有component有相同的covariance,diag:每个component有各自的diagonal covariance matrix,spherical:每个component有自己的covariance}
#tol:目标值达到tol,停止迭代
#reg_covar:Non-negative regularization added to the diagonal of covariance. Allows to assure that the covariance matrices are all positive.???
#max_iter:最大迭代次数
#n_init:执行几个初始值
#init_params:用来初始化component_weight,mean,covariance的方法。{kmeans,random}???
#weight_init:各个component的权重初始值
#means_init:各个component的平均值初始值
#precisions_init:各个component的精确度初始值,precisions为inverse of covariance
#random_state:给定一个随机状态
#warm_start:用上一次的结果作为初始值
#verbose:Enable verbose output.
#verbose_interval:Number of iteration done before the next print.

#attributes
.weights_   #各个component的权重
.means_   #各个component的平均值
.covariances_   #各个component的协方差
.precisions_  #各个component的precision
.precisions_cholesky_  #The cholesky decomposition of the precision matrices of each mixture component.
.converged_ #bool:是否达到收敛
.n_iter_  #迭代次数
.lower_bound_  #Lower bound value on the log-likelihood of the best fit of EM.

#method
aic(X)	#Akaike information criterion for the current model on the input X.
bic(X)	#Bayesian information criterion for the current model on the input X.
fit(X[, y])	#Estimate model parameters with the EM algorithm.
fit_predict(X[, y])	#Estimate model parameters using X and predict the labels for X.
get_params([deep])	#Get parameters for this estimator.
predict(X)	#Predict the labels for the data samples in X using trained model.
predict_proba(X)	#Predict posterior probability of each component given the data.
sample([n_samples])	#Generate random samples from the fitted Gaussian distribution.
score(X[, y])	#Compute the per-sample average log-likelihood of the given data X.
score_samples(X)	#Compute the weighted log probabilities for each sample.
set_params(**params)	  #Set the parameters of this estimator.

[待更新]reg_covar工作原理
[待更新]init_params:kmeans如何应用于初始化

高斯混合模型

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Hyperopt-sklearn是基于scikit-learn项目的一个子集,其全称是:Hyper-parameter optimization for scikit-learn,即针对scikit-learn项目的超级参数优化工具。由于scikit-learn是基于Python的机器学习开源框架,因此Hyperopt-sklearn也基于Python语言。Hyperopt-sklearn的文档称:对于开发者而言,针对不同的训练数据挑选一个合适的分类器(classifier)通常是困难的。而且即使选好了分类器,后面的参数调试过程也相当乏味和耗时。更严重的是,还有许多情况是开发者好不容易调试好了选定的分类器,却发现一开始的选择本身就是错误的,这本身就浪费了大量的精力和时间。针对该问题,Hyperopt-sklearn提供了一种解决方案。Hyperopt-sklearn支持各种不同的搜索算法(包括随机搜索、Tree of Parzen Estimators、Annealing等),可以搜索所有支持的分类器(KNeightborsClassifier、KNeightborsClassifier、SGDClassifier等)或者在给定的分类器下搜索所有可能的参数配置,并评估最优选择。并且Hyperopt-sklearn还支持多种预处理流程,包括TfidfVectorizer,Normalzier和OneHotEncoder等。那么Hyperopt-sklearn的实际效果究竟如何?下表分别展示了使用scikit-learn默认参数和Hyperopt-sklearn优化参数运行的分类器的F-score分数,数据源来自20个不同的新闻组稿件。可以看到,经过优化的分类器的平均得分都要高于默认参数的情况。另外,Hyperopt-sklearn的编码量也很小,并且维护团队还提供了丰富的参考样例。 标签:Hyperopt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Sarah ฅʕ•̫͡•ʔฅ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值