小编mad*_*127的帖子

如何修复使用 sklearn.mixture.GaussianMixture 拟合 GMM 时的 ValueError?

我试图使用 GaussianMixture 模型进行图像分割,所以我使用了 2 个组件,协方差矩阵 type="full" 并尝试使用 anaconda 附带的 Spyder3.6 运行。这是代码:

from scipy.misc import imread, imshow
from sklearn.mixture import GaussianMixture as GMM
import graph_tool.all as gt
from graph_tool.all import *

X=imread('2.jpg')
old=X.shape
X=X.reshape(-1,3)
gmm=GMM(covariance_type='full', n_components=2)
gmm.fit(X)
clusters=gmm.predict(X)
clusters=clusters.reshape(old[0],old[1])
Run Code Online (Sandbox Code Playgroud)

但它显示 ValueError 和正定异常,我不明白为什么?这是错误的痕迹。

`

回溯(最近一次调用最后一次):

文件“/home/madhur/anaconda3/lib/python3.6/site-packages/sklearn/mixture/gaussian_mixture.py”,第 318 行,在 _compute_ precision_cholesky cov_chol = linalg.cholesky(covariance, lower=True)
文件“/home/ madhur/anaconda3/lib/python3.6/site-packages/scipy/linalg/decomp_cholesky.py”,第 81 行,在 cholesky check_finite=check_finite 中)
文件“/home/madhur/anaconda3/lib/python3.6/site-packages /scipy/linalg/decomp_cholesky.py",第 30 行,在 _cholesky 中
引发 LinAlgError("%d-th 前导次要非正定" % info)
numpy.linalg.linalg.LinAlgError:第 2 个前导次要非正定

在处理上述异常的过程中,又出现了一个异常:

回溯(最近一次调用最后一次):
文件“/home/madhur/Desktop/Project/graphcutmaterials/test.py”,第 19 行,在 gmm.fit(X)
文件“/home/madhur/anaconda3/lib/python3.6”中/site-packages/sklearn/mixture/base.py”,第 …

numpy image-processing python-3.x scikit-learn gmm

3
推荐指数
1
解决办法
5428
查看次数

在函数C++ 14中包含STL头文件

tl; dr:我可以以某种方式使这段代码在C++ 14(GCC 6.3)中运行吗?

int main(){
    #include<vector>
    std::vector<int> v{1,2,3};
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但下面的代码工作得很好!

#include <iostream>
using namespace std;

int main() {
    #include<cstdio>
    using namespace __gnu_cxx;
    printf("Hello world\n.");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用C++ 14(gcc-6.3)代码时不会编译错误消息

 error: 'namespace' definition is not allowed here
 namespace std
 ^~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

我为什么要这样做?

我无权访问允许编码的函数.我不能在全球范围内#include.

UPD:更改为cstdlib也有效问题不是由标题保护(根据我)排除,而是名称空间问题.因为C++头文件具有命名空间std,而c头文件没有.我想问一下命名空间问题是否有一些调整?

c++ stl c++14

0
推荐指数
1
解决办法
125
查看次数

标签 统计

c++ ×1

c++14 ×1

gmm ×1

image-processing ×1

numpy ×1

python-3.x ×1

scikit-learn ×1

stl ×1