---
title: Covariance
description: "| 模型接口类别 | 函数接口 |"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/bds/kunpengbdssparkml_16_0025.html
sourcePath: /source/zh/kunpengboostkithistory/2200/bds/kunpengbdssparkml_16_0025.html
indexId: 6a36e7897ec76dbcb14a50181e769ebe3851c717999d7415cf1b3bb9c0ccbb8573
---
# Covariance

| 模型接口类别 | 函数接口 |
| --- | --- |
| MLlib RowMatrix API | def computeCovariance (): Matrix |


#### MLlib RowMatrix API

- 功能描述
  输入RDD[Vector]形式的矩阵，输出协方差矩阵。


- 输入输出

  1. 包名：org.apache.spark.mllib.linalg.distributed
  2. 类名：RowMatrix
  3. 方法名：computeCovariance
  4. 输入：RowMatrix，输入矩阵| 参数名称 | 取值类型 | 描述 |
| --- | --- | --- |
| rows | RDD[Vector] | 矩阵，以行为单位进行存储 |
| nRows | Long | 行数 |
| nCols | Int | 列数 |


  5. 算法参数
    代码接口示例： 1 2 val matrix = new RowMatrix(data) val covMat = matrix.computeCovariance()

  6. 输出：协方差矩阵Matrix| 参数名称 | 取值类型 | 描述 |
| --- | --- | --- |
| Mat | Matrix | 协方差矩阵 |


- 使用样例
  1 val mat = mat.computeCovariance ()
