Module_Statistics_Others_zh - vorcyc/Vorcyc.Mathematics GitHub Wiki
Vorcyc.Mathematics.Statistics.Others 是一个提供其他统计函数的类,包括协方差、相关系数和线性回归分析。
以下方法均位于类 :Vorcyc.Mathematics.Statistics.Others
📒目录
Vorcyc.Mathematics.Statistics.Others 是一个提供其他统计函数的类,包括协方差、相关系数和线性回归分析。
-
public static T Covariance<T>(this Span<T> x, Span<T> y) where T : INumber<T>- 计算两组数据的协方差。
- 参数:
-
x: 第一组数据。 -
y: 第二组数据。
-
- 返回值: 两组数据的协方差。
-
public static T CorrelationCoefficient<T>(this Span<T> x, Span<T> y) where T : IFloatingPointIeee754<T>- 计算两组数据的相关系数。
- 参数:
-
x: 第一组数据。 -
y: 第二组数据。
-
- 返回值: 两组数据的相关系数。
-
public static (T Slope, T Intercept) LinearRegression<T>(this Span<T> x, Span<T> y) where T : IFloatingPointIeee754<T>- 实现简单的线性回归分析。
- 参数:
-
x: 自变量数据。 -
y: 因变量数据。
-
- 返回值: 包含回归系数和截距的元组。
以下是一个使用 Others 类中多个方法的示例,并在示例中加入了注释:
using System;
using Vorcyc.Mathematics.Statistics;
public class OthersExample
{
public static void Main()
{
// 定义两组数据
Span<double> x = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0 };
Span<double> y = new double[] { 2.0, 4.0, 6.0, 8.0, 10.0 };
// 计算协方差
double covariance = x.Covariance(y);
Console.WriteLine("Covariance: " + covariance);
// 计算相关系数
double correlationCoefficient = x.CorrelationCoefficient(y);
Console.WriteLine("Correlation Coefficient: " + correlationCoefficient);
// 进行线性回归分析
var (slope, intercept) = x.LinearRegression(y);
Console.WriteLine($"Linear Regression: Slope = {slope}, Intercept = {intercept}");
}
}