C# chart.DataManipulator.FinancialFormula()公式的使用 线性回归预测方法
最近翻阅资料,找到 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()公式的使用 线性回归预测方法的更多相关文章
- Tensorflow 线性回归预测房价实例
在本节中将通过一个预测房屋价格的实例来讲解利用线性回归预测房屋价格,以及在tensorflow中如何实现 Tensorflow 线性回归预测房价实例 1.1. 准备工作 1.2. 归一化数据 1.3. ...
- MathType给公式加三角着重号的方法
MathType是一款出色的数学公式编辑器,不仅可以兼容word,还与PPT也兼容.它也可以在PPT中编辑出非常漂亮的公式,再加上PPT本身所具有的动画.颜色.显示等功能,在演示数学公式时非常的精美. ...
- 机器学习01:使用scikit-learn的线性回归预测Google股票
这是机器学习系列的第一篇文章. 本文将使用Python及scikit-learn的线性回归预测Google的股票走势.请千万别期望这个示例能够让你成为股票高手.下面按逐步介绍如何进行实践. 准备数据 ...
- winform Chart控件 获取鼠标处坐标值方法
Chart控件本身功能强大,应用广泛,因此其属性.方法也很多.此处介绍在很多应用中需要查看鼠标位置处坐标值的一些方法 1,调用Chart事件 GetToolTip 利用ToolTipEventArg ...
- 公式编辑器MathType基本使用方法总结----应付本科毕业论文完全没问题啦^_^
本人计算数学专业毕业,写毕业论文和外文翻译的时候会遇到大量公式需要编辑,而且学校一般都要求用word.但是Word自带的公式编辑器只支持一种字体,当公式中涉及到特殊字体就不太方便了.如果用Latex来 ...
- 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. ...
- 数值积分:基于牛顿-柯茨公式的定步长和自适应积分方法 [MATLAB]
#先上代码后补笔记# #可以直接复制粘贴使用的MATLAB函数!# 1. 定步长牛顿-柯茨积分公式 function [ integration ] = CompoInt( func, left, r ...
- 线性回归预测PM2.5----台大李宏毅机器学习作业1(HW1)
一.作业说明 给定训练集train.csv,要求根据前9个小时的空气监测情况预测第10个小时的PM2.5含量. 训练集介绍: (1)CSV文件,包含台湾丰原地区240天的气象观测资料(取每个月前20天 ...
- Python 实现多元线性回归预测
一.二元输入特征线性回归 测试数据为:ex1data2.txt ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ...
随机推荐
- canvas之画一条线段
var canvas=document.getElementById("canvas"); //设置绘图环境 var cxt=canvas.getContext('2d'); // ...
- 侯捷stl学习笔记链接
http://www.cnblogs.com/ranjiewen/category/799058.html http://www.cnblogs.com/ranjiewen/p/8260275.htm ...
- 如何实现查询显示N个工作日有效期内的数据
功能点分析:要显示N个工作日有效期内的数据,需要考虑: 1. 可以给每条数据增加一个有效期时间字段,查询时只显示有效期之前的数据,如有效期为七天,数据的创建时间是2014-07-21,那七个工作日有效 ...
- Tkinter Cursors
Tkinter Cursors: Python的Tkinter的支持很多不同的鼠标光标的数字.确切的图形可能会有所不同,根据您的操作系统. 这里是大量有趣的的名单: "arrow&q ...
- 新版Eclipse使用遇到的问题总结
1.SDK下载很慢. 配置SDK代理,速度像飞一样.建议先把20-24下完,不然后面遇到很多问题. 2.support-v7的问题 例如res\values\styles.xml:4: error: ...
- keil里面填数据
编译后寄存器和堆栈的内存数据可以直接写进去的. 寄存器,双击就可以,注意里面是十六进制 堆栈,也是十六进制,八位的 00 00 00 00 ,但这个是从右到左的,比如0x00000006 应该填 06 ...
- Rhythmk 一步一步学 JAVA (18) Axis2 创建 WebService
一 > 环境配置 1.下载Axis2: 目前版本为 1.6.2 下载地址: http://axis.apache.org/axis2/java/core/ 下载 axis2-1.6.2-bin. ...
- 使用PowerMap生成地图图文
地区 GDP(亿)广东省 80854江苏省 77388山东省 68024浙江省 47251河南省 40471四川省 32934湖北省 32665河北省 ...
- malloc()与calloc区别 (转)
另外说明: 1.分配内存空间函数malloc 调用形式: (类型说明符*) malloc (size) 功能:在内存的动态存储区中分配一块长度为"size" 字节的连续区域.函数的 ...
- Java ArrayList的不同排序方法
本文由 ImportNew - 温布利往事 翻译自 dzone.欢迎加入翻译小组.转载请见文末要求. 由于其功能性和灵活性,ArrayList是 Java 集合框架中使用最为普遍的集合类之一.Arra ...