最近翻阅资料,找到 chart.DataManipulator.FinancialFormula()公式的使用,打开另一扇未曾了解的窗,供大家分享一下。

一 DataManipulator类

运行时,执行数据操作。此类是通过chart中DataManipulator属性对外公开的。

在C#中的继承关系如下:

System.Object

System.Web.UI.DataVisualization.Charting.DataFormula

System.Web.UI.DataVisualization.Charting.DataManipulator

《命名空间:System.Web.UI.DataVisualization.Charting》

《程序集:System.Web.DataVisualization(在 System.Web.DataVisualization.dll 中)》

在DataManipulator属性中囊括了很多数学计算方法(大多都是针对图表的数据序列展开的)以下是这样一个列子:

double result = Chart1.DataManipulator.Statistics.Mean("Series1");平均值函数

double result = Chart1.DataManipulator.Statistics.Median("Series1");中值函数

 StatisticFormula 类计算统计公式。

二、DataFormula.FinancialFormula 方法

使用指定的参数从公式模块调用方法。

重载此成员。有关此成员的完整信息(包括语法、用法和示例),请单击重载列表中的相应名称。

在这里特别讲到的是预测函数功能的实现情况。

预测公式尝试根据历史数据找出拟合度最佳的回归函数,然后根据最拟合的函数预测最可能的未来数据值。

Chart.DataManipulator.FinancialFormula(
    FinancialFormula.Forecasting,
    "RegressionType,Period,ApproxError,ForecastError",
    "Historical",
    "Forecast,UpperError,LowerError")

三 预测函数的语法分析说明

此公式采用四个可选参数。

RegressionType

回归类型。使用一个数字来指示特定次数的多元回归,或者使用以下值之一指定不同的回归类型:Linear、Exponential、Logarithmic、Power。默认值为 2,与指定 Linear 等效。

Period

预测时段。公式会预测此指定的未来天数内的数据变化。默认值为序列长度的一半。

ApproxError

是否输出近似误差。如果设置为 false,则输出误差序列不包含相应历史数据的数据。默认值为 true。

ForecastError

是否输出预测误差。如果设置为 false,并且 ApproxError 设置为 true,则输出误差序列将包含所有预测数据点的近似误差。默认值为 true。

输入值:

此公式采用一个输入 Y 值。

Historical:用于预测的历史数据。

输出值:

此公式输出三个 Y 值。

Forecast:预测测值。

UpperError:上限误差。

LowerError:下限误差。
下面的示例以 Series1 (Series1:Y) 作为输入,在 Series2 上输出预测值 (Series2:Y),在 Series3 上输出误差范围(Series3:Y、Series3:Y2)。该示例采用二次多元回归,预测期间为 40 天。
Chart1.DataManipulator.FinancialFormula (FinancialFormula.Forecasting, "2,40,true,true", "Series1:Y", "Series2:Y,Series3:Y,Series3:Y2");

在编程的过程中,注意原始历史数据的输入,要求X轴的间隔是一定的,否则影响数据的回归分析

四:以下是自己编写的线性回归预测方法的一个公用类

using System.Drawing;
using System.Windows.Forms.DataVisualization.Charting;
using System; namespace WindowsFormsApplication8
{
class RegressionModelClass
{
#region 字段
double[] sourceData_X = new double[4]; // 样本数据 X 轴坐标值
double[] sourceData_Y = new double[4]; // 样本数据 Y 轴坐标值 double[] predictData_Y = new double[8]; // 预测的未来数据的 Y 轴坐标值
int n = 4; // 样本数据的个数 // Chart
System.Windows.Forms.DataVisualization.Charting.Chart chart_temp = new System.Windows.Forms.DataVisualization.Charting.Chart(); #endregion /// <summary>
/// 构造函数
/// </summary>
public RegressionModelClass(double[] data_x, double[] data_y)
{
for (int i = 0; i < n;i++)
{
sourceData_X[i] = data_x[i];
sourceData_Y[i] = data_y[i];
} InitialChart(chart_temp, sourceData_X, sourceData_Y);
} // 初始化 Chart 控件
private void InitialChart(System.Windows.Forms.DataVisualization.Charting.Chart chart, double[] data_x, double[] data_y)
{
#region 1. Title 设置
Title title = new Title(); //* 实例化
title.Text = "信息预测";
//** 关联
chart.Titles.Add(title); //* 当使用这种重载方式时,可以将属性传递
#endregion #region 2. ChartArea 设置
ChartArea chartarea1 = new ChartArea(); //* 实例化
chartarea1.Name = "chartarea1"; //* ChartArea 的唯一名称
// 关联
chart.ChartAreas.Add(chartarea1); //重要//使用这种重载方法
#endregion #region 3. 坐标轴设置
#region 3.1 X轴
Axis axis_X = new Axis();
axis_X.IntervalType = DateTimeIntervalType.Days;
axis_X.Title = "时 间"; //* 轴的标题
// ** 关联
chart.ChartAreas[0].AxisX = axis_X;
chart.ChartAreas[0].AxisX.Enabled = AxisEnabled.True;
#endregion #region 3.2.1 深度 -- Y 轴
Axis axisY_depth = new Axis();
axisY_depth.Title = "深度";
axisY_depth.LineColor = Color.Black;
axisY_depth.ArrowStyle = AxisArrowStyle.None;
axisY_depth.TextOrientation = TextOrientation.Stacked;
axisY_depth.TitleFont = new Font("微软雅黑", 14F, FontStyle.Bold);
axisY_depth.TitleForeColor = Color.Black;
axisY_depth.TitleAlignment = StringAlignment.Far;
axisY_depth.IsLabelAutoFit = false; axisY_depth.IntervalType = DateTimeIntervalType.Number;
axisY_depth.IsStartedFromZero = false;
axisY_depth.Minimum = 0;
axisY_depth.Maximum = 10;
axisY_depth.IntervalAutoMode = IntervalAutoMode.FixedCount;
axisY_depth.InterlacedColor = Color.Red; // ** 关联
chart.ChartAreas[0].AxisY = axisY_depth;
chart.ChartAreas[0].AxisY.Enabled = AxisEnabled.True;
#endregion #endregion #region 4. Series 设置 Series series = new Series();
series.Name = "样本数据曲线";
series.ChartType = SeriesChartType.Line;
series.XAxisType = AxisType.Primary;
series.YAxisType = AxisType.Primary;
// important
series.XValueType = ChartValueType.DateTime;
series.YValueType = ChartValueType.Double;
series.Enabled = true; //关联
series.ChartArea = chart.ChartAreas[0].Name;
chart.Series.Clear();
chart.Series.Add(series); // 注意要使用这个重载方法,不应该使用 Add(string)重载方法
#endregion #region 5. Points 设置 // 清除所有数据点
chart.Series[0].Points.Clear(); // 添加数据点
int m = data_x.Length;
for (int i = 0; i < m; i++)
{
chart.Series[0].Points.AddXY(data_x[i], data_y[i]);
}
#endregion
} /// <summary>
/// 得到基于回归分析预测的数据
/// </summary>
///
public double[] GetPredictData()
{
Series trendSeries = new Series();
trendSeries.Name = "trend";
trendSeries.ChartType = SeriesChartType.Line; // 关联
trendSeries.ChartArea = chart_temp.ChartAreas[0].Name;
chart_temp.Series.Add(trendSeries); string typeRegression = "2";
// The number of days for Forecasting (备注:该数字对应的单位与X轴的数据间隔单位有关,并不一定是“天”)
string forecasting = "4";
string error = "false";
string forecastingError = "false";
string parameters = typeRegression + ',' + forecasting + ',' + error + ',' + forecastingError; chart_temp.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, parameters, chart_temp.Series[0], chart_temp.Series["trend"]); for (int i = 0; i < 8; i++) // 共4个预测值
{
predictData_Y[i] = Math.Round(chart_temp.Series["trend"].Points[i].YValues[0], 5); // chart.Series["trend"]共8个数据点
} return predictData_Y;
}
}
}

C# chart.DataManipulator.FinancialFormula()公式的使用 线性回归预测方法的更多相关文章

  1. Tensorflow 线性回归预测房价实例

    在本节中将通过一个预测房屋价格的实例来讲解利用线性回归预测房屋价格,以及在tensorflow中如何实现 Tensorflow 线性回归预测房价实例 1.1. 准备工作 1.2. 归一化数据 1.3. ...

  2. MathType给公式加三角着重号的方法

    MathType是一款出色的数学公式编辑器,不仅可以兼容word,还与PPT也兼容.它也可以在PPT中编辑出非常漂亮的公式,再加上PPT本身所具有的动画.颜色.显示等功能,在演示数学公式时非常的精美. ...

  3. 机器学习01:使用scikit-learn的线性回归预测Google股票

    这是机器学习系列的第一篇文章. 本文将使用Python及scikit-learn的线性回归预测Google的股票走势.请千万别期望这个示例能够让你成为股票高手.下面按逐步介绍如何进行实践. 准备数据 ...

  4. winform Chart控件 获取鼠标处坐标值方法

    Chart控件本身功能强大,应用广泛,因此其属性.方法也很多.此处介绍在很多应用中需要查看鼠标位置处坐标值的一些方法 1,调用Chart事件  GetToolTip 利用ToolTipEventArg ...

  5. 公式编辑器MathType基本使用方法总结----应付本科毕业论文完全没问题啦^_^

    本人计算数学专业毕业,写毕业论文和外文翻译的时候会遇到大量公式需要编辑,而且学校一般都要求用word.但是Word自带的公式编辑器只支持一种字体,当公式中涉及到特殊字体就不太方便了.如果用Latex来 ...

  6. MATLAB实现多元线性回归预测

    一.简单的多元线性回归: data.txt ,230.1,37.8,69.2,22.1 ,44.5,39.3,45.1,10.4 ,17.2,45.9,69.3,9.3 ,151.5,41.3,58. ...

  7. 数值积分:基于牛顿-柯茨公式的定步长和自适应积分方法 [MATLAB]

    #先上代码后补笔记# #可以直接复制粘贴使用的MATLAB函数!# 1. 定步长牛顿-柯茨积分公式 function [ integration ] = CompoInt( func, left, r ...

  8. 线性回归预测PM2.5----台大李宏毅机器学习作业1(HW1)

    一.作业说明 给定训练集train.csv,要求根据前9个小时的空气监测情况预测第10个小时的PM2.5含量. 训练集介绍: (1)CSV文件,包含台湾丰原地区240天的气象观测资料(取每个月前20天 ...

  9. Python 实现多元线性回归预测

    一.二元输入特征线性回归 测试数据为:ex1data2.txt ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ...

随机推荐

  1. centos开机提示CPU无法识别的问题

    centos版本和对应cpu兼容性,官方网址: https://access.redhat.com/support/policy/intel Red Hat Enterprise Linux Vers ...

  2. 【转】WebAPI使用多个xml文件生成帮助文档

    来自:http://www.it165.net/pro/html/201505/42504.html 一.前言 上篇有提到在WebAPI项目内,通过在Nuget里安装(Microsoft.AspNet ...

  3. 脱壳系列(一) - CrypKeySDK 壳

    程序: 运行 用 PEiD 载入程序 PEid 显示找不到相关的壳 脱壳: 用 OD 载入程序 这个是壳的入口地址 因为代码段的入口地址为 00401000 这三个是壳增加的区段 按 F8 往下走程序 ...

  4. 开始使⽤ZooKeeper的API

    在之前的章节中,我们使用zkCli工具介绍了ZooKeeper的基本操作.从本章开始,我们将会看到在应用中如何通过API来进行操作.首先介绍一下如何使用ZooKeeper的API进行开发,展示如何创建 ...

  5. C#接口的三种实现方式

    转自原文C#接口的三种实现方式 public interface MyInterface { /// 下面三个方法的签名都是 /// .method public hidebysig newslot ...

  6. Splash Screen 加载窗体 [not finished]

    对于windows开 发人员来说在打开VS开发工具时,总是先呈现一个SplashScreen界面,登上几秒钟后才打开VS的主界面.这样的效果一般是在主界面需要加载大量 资源,为避免主界面变成“死”界面 ...

  7. 关于struts2.x中(警告: Could not find property [struts.valueStack])的解决方法

    出现“警告: Could not find property [struts.valueStack]”这样的问题,是由于少引用了log4j.jar包,不过,不引用也不影响使用.看个人的爱好了.

  8. 3.Hadoop集群搭建之Zookeeper安装

    前期准备 下载Zookeeper 3.4.5 若无特殊说明,则以下操作均在master节点上进行 1. 解压Zookeeper #直接解压Zookeeper压缩包 tar -zxvf zookeepe ...

  9. 【原】Coursera—Andrew Ng机器学习—Week 5 习题—Neural Networks learning

    课上习题 [1]代价函数 [2]代价函数计算 [3] [4]矩阵的向量化 [5]梯度校验 Answer:(1.013 -0.993) / 0.02 = 3.001 [6]梯度校验 Answer:学习的 ...

  10. hibernate nhibernate sqlserver数据库的默认值冲突解决

    数据库中一个字段的默认值设为0,当用hibernate插入数据时,没有对该字段进行操作,结果该字段居然不是0,而是空.后来google了一下,发现应该在.hbm.xml文件中添加一些参数定义(示例中的 ...