推荐一个开放源。净的统计数据库[封闭]
-
02-07-2019 - |
题
我需要计算出平均值,标准偏差,中位数等于一堆数字数据。是否有一个良好的开放源。净图书馆我可以使用?我已经找到NMath但它不是免费的并可以矫枉过正为我需要。
解决方案
我发现这个的演示网站。它看起来像一个良好C#级处理的大多数基本统计的功能。
其他提示
你必须小心。如果浮点运算是完美的,有几种计算标准偏差的方法会给出相同的答案。它们对于某些数据集都是准确的,但在某些情况下,有些数据集远远优于其他数据集。
我在这里看到的方法是最有可能给出错误答案的方法。我自己用它直到它撞到我身上。
请参阅比较三计算标准差的方法。
查看 MathNet ,它不是专门用于统计数据,但可能有一些有用的功能为了你想要的东西
Apache Maths.Common 并通过 IKVM 。
我决定写自己的更快,那就是我需要的。这是代码......
/// <summary>
/// Very basic statistical analysis routines
/// </summary>
public class Statistics
{
List<double> numbers;
public double Sum { get; private set; }
public double Min { get; private set; }
public double Max { get; private set; }
double sumOfSquares;
public Statistics()
{
numbers = new List<double>();
}
public int Count
{
get { return numbers.Count; }
}
public void Add(double number)
{
if(Count == 0)
{
Min = Max = number;
}
numbers.Add(number);
Sum += number;
sumOfSquares += number * number;
Min = Math.Min(Min,number);
Max = Math.Max(Max,number);
}
public double Average
{
get { return Sum / Count; }
}
public double StandardDeviation
{
get { return Math.Sqrt(sumOfSquares / Count - (Average * Average)); }
}
/// <summary>
/// A simplistic implementation of Median
/// Returns the middle number if there is an odd number of elements (correct)
/// Returns the number after the midpoint if there is an even number of elements
/// Sorts the list on every call, so should be optimised for performance if planning
/// to call lots of times
/// </summary>
public double Median
{
get
{
if (numbers.Count == 0)
throw new InvalidOperationException("Can't calculate the median with no data");
numbers.Sort();
int middleIndex = (Count) / 2;
return numbers[middleIndex];
}
}
}
AForge.NET 具有AForge.Math名称空间,提供一些基本的统计功能:直方图,平均值,中位数, stddev,entropy。
如果您只需要进行一次性数字运算,电子表格就是您最好的工具。从C#中吐出一个简单的CSV文件是很简单的,然后可以在Excel(或其他)中加载:
class Program
{
static void Main(string[] args)
{
using (StreamWriter sw = new StreamWriter("output.csv", false, Encoding.ASCII))
{
WriteCsvLine(sw, new List<string>() { "Name", "Length", "LastWrite" });
DirectoryInfo di = new DirectoryInfo(".");
foreach (FileInfo fi in di.GetFiles("*.mp3", SearchOption.AllDirectories))
{
List<string> columns = new List<string>();
columns.Add(fi.Name.Replace(",", "<comma>"));
columns.Add(fi.Length.ToString());
columns.Add(fi.LastWriteTime.Ticks.ToString());
WriteCsvLine(sw, columns);
}
}
}
static void WriteCsvLine(StreamWriter sw, List<string> columns)
{
sw.WriteLine(string.Join(",", columns.ToArray()));
}
}
然后你可以'启动excel output.csv'并使用诸如“= MEDIAN(B:B)”,“= AVERAGE(B:B)”,“= STDEV(B:B)之类的函数)&QUOT ;.你得到图表,直方图(如果你安装分析包)等等。
以上并不能解决所有问题;广义CSV文件比您想象的更复杂。但它“足够好”了。对于我做的大部分分析。
不隶属于 StackOverflow