728x90
반응형
728x170
▶ 상관 계수 구하기 예제
using System;
using System.Collections.Generic;
List<double> xList = new List<double>() { 5 , 10, 15, 20, 30, 20, 30 };
List<double> yList = new List<double>() { 10, 40, 20, 30, 40, 10, 20 };
double correlationCoefficient = GetCorrelationCoefficient(xList, yList);
Console.WriteLine(correlationCoefficient);
728x90
▶ 상관 계수 구하기
using System;
using System.Collections.Generic;
#region 상관 계수 구하기 - GetCorrelationCoefficient(xList, yList)
/// <summary>
/// 상관 계수 구하기
/// </summary>
/// <param name="xList">X 리스트<param>
/// <param name="yList">Y 리스트</param>
/// <returns>상관 계수</returns>
public double GetCorrelationCoefficient(List<double> xList, List<double> yList)
{
double result = 0d;
double multiplyXYSigma = 0d;
double xSigma = 0d;
double ySigma = 0d;
double xPowSigma = 0d;
double yPowSigma = 0d;
double xListCount = xList.Count;
for(int i = 0; i < xList.Count; i++)
{
multiplyXYSigma += (xList[i] * yList[i]);
xSigma += xList[i];
ySigma += yList[i];
xPowSigma += Math.Pow(xList[i], 2);
yPowSigma += Math.Pow(yList[i], 2);
}
result = ((xListCount * multiplyXYSigma) - (xSigma * ySigma)) / (Math.Sqrt(((xListCount * xPowSigma) - Math.Pow(xSigma, 2)) * ((xListCount * yPowSigma) - Math.Pow(ySigma, 2))));
return result;
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] WebClient 클래스 : FTP 파일 업로드하기 (0) | 2014.11.28 |
---|---|
[C#/COMMON] Win32 API 호출시 에러 코드 구하기 (0) | 2014.11.27 |
[C#/COMMON] Environment 클래스 : 프로그램 인자 구하기 (0) | 2014.11.27 |
[C#/COMMON] 2 제곱 수 여부 구하기 (0) | 2014.11.27 |
[C#/COMMON] 소수(素數) 리스트 구하기 (0) | 2014.11.27 |
[C#/COMMON] 상관 계수 구하기 (0) | 2014.11.27 |
[C#/COMMON] 최대 공약수 구하기 (0) | 2014.11.27 |
[C#/COMMON] 팩토리얼 구하기 (0) | 2014.11.27 |
[C#/COMMON] 컬럼 인덱스 구하기 (0) | 2014.11.27 |
[C#/COMMON] 행 인덱스 구하기 (0) | 2014.11.27 |
[C#/COMMON] 행 수 구하기 (0) | 2014.11.27 |
댓글을 달아 주세요