python - 使用 sklearn 中的拟合进行协方差估计时出错

标签 python machine-learning scikit-learn curve-fitting

我有一个变量xcin,其中包含数组形式的数据。我正在尝试使用 GraphLassoCV 中的 fit() 来拟合这些数据。

xcin 中存在的数据:

[ 0.722    0.32202  0.70102  0.7414   0.18204  0.01132  0.171    0.723
  0.722    0.52605  0.70102  0.7414   0.29253  0.95     0.729    0.7414
  0.74999  0.7412   0.454    0.7414   0.15122  0.7414   0.65992  0.723
  0.70102  0.45209  0.521    0.7412   0.92412  0.01403  0.45203  0.723
  0.9303   0.454    0.74999  0.5232   0.6309   0.1712   0.7414   0.221
  0.70102  0.851    0.241    0.01122  0.749    0.749    0.24232  0.454
  0.80904  0.454    0.40106  0.74999  0.74999  0.17123  0.74999  0.7412
  0.271    0.7414   0.55204  0.7414   0.5259   0.7414   0.749    0.7414
  0.722    0.28133  0.9219   0.749    0.729    0.749    0.3311   0.45201
  0.9303   0.45201  0.722    0.6304   0.722    0.40106  0.45205  0.18109
  0.722    0.749    0.749    0.5259   0.40107  0.40106  0.36911  0.7414
  0.7412   0.74999  0.154    0.851    0.722    0.154    0.722    0.74999
  0.29253  0.729    0.7412   0.6309 ]

我尝试使用以下代码:

xcin =np.array([df['xcin']])/100000.0
# Learn a graphical structure from the correlations
edge_model = covariance.GraphLassoCV()
X = xcin.copy().T
X /= X.std(axis=0)
edge_model.fit(X)

但是我在 edge_model.fit() 行上遇到错误:

ValueError: Found array with 1 feature(s) (shape=(100, 1)) while a minimum of 2 is required by GraphLassoCV.

有人可以解释一下如何解决这个问题吗?

我正在尝试遵循此处演示的方法 (http://scikit-learn.org/stable/auto_examples/applications/plot_stock_market.html#sphx-glr-auto-examples-applications-plot-stock-market-py) 来生成类似类型的可视化。

最佳答案

您的数据为 100x1,这意味着您有 100 个数字。所以这要么是 100 个 1dim 数据的样本,要么是 100 个暗淡数据的 1 个样本。无论哪种方式,此类数据都没有协方差矩阵的概念,您至少需要 2 个样本和 2 个维度。只有一维时,您唯一可以计算的就是方差。特别是,此行为在 source code 中进行了评论。

# Covariance does not make sense for a single feature
X = check_array(X, ensure_min_features=2, estimator=self)

关于python - 使用 sklearn 中的拟合进行协方差估计时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40452861/

相关文章:

python - 对 cairo-drawn Canvas 实现缩放的最有效方法是什么?

machine-learning - 如何在 TensorFlow 中为卷积层正确创建批量归一化层?

python - 用一些不在训练集中的词预测分类(朴素贝叶斯)

python - load_digits() 和 fetch_mldata ("MNIST Original"有什么区别)

machine-learning - Keras 自定义层 2D 输入 -> 2D 输出

python - 大数据集的多标签分类

python - prime_factorize(1) -> ? (Python 错误信号)

python - 为什么 django ORM 比原始 SQL 慢得多

Python 将 XML 同级数据放入字典中

parameters - 训练SVM模型时如何调整参数