ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:79.41KB ,
资源ID:26835090      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/26835090.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(最小二乘法+.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

最小二乘法+.docx

1、最小二乘法+ 数据挖掘-最小二乘法预测完成日期 2014年 4月实验一 成绩预测1实验目的:学会使用最小二乘法进行数据预测2实验内容:根据给出的一系列期中期末成绩,使用最小二乘法求由学生期中成绩预测学生期末成绩的方程,并建立应用程序实现:方程的建立算法;绘制X,Y关系曲线图;提供新数据的预测功能。3实验环境:3.1硬件环境CPU:P41.8GHz内存:4G硬盘空间:40GB3.2软件环境操作系统:Windows7旗舰版开发环境配置:Eclipse应用服务器配置:jdk1.6.0_324程序设计思路及代码编程程序设计思路:使用adodc控件连接数据库,在程序运行初始便从表中将原有数据显示在网格中

2、。界面中设置两个文本框,一个用于输入中期成绩后一个用于输出预测期末成绩。代码编程:import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.Swi

3、ngUtilities;import javax.swing.UIManager;import javax.swing.table.DefaultTableModel;import org.dyno.visual.swing.layouts.Constraints;import org.dyno.visual.swing.layouts.GroupLayout;import org.dyno.visual.swing.layouts.Leading;/VS4E - DO NOT REMOVE THIS LINE!public class window extends JFrame privat

4、e static final long serialVersionUID = 1L; private JLabel jLabel0; private JTable jTable0; private JScrollPane jScrollPane0; private JLabel jLabel1; private JLabel jLabel4; private JLabel jLabel3; private JTextField jTextField1; private JTextField jTextField2; private JButton jButton0; private JText

5、Field jTextField0; private JLabel jLabel2; private JButton jButton1; double x = 72, 50, 81, 74, 94, 86, 59, 83, 65, 33, 88, 81 ; double y = 84, 63, 77, 78, 90, 75, 49, 79, 77, 52, 74, 90 ; double z=0; private static final String PREFERRED_LOOK_AND_FEEL = javax.swing.plaf.metal.MetalLookAndFeel; publ

6、ic window() initComponents(); private void initComponents() setLayout(new GroupLayout(); add(getJLabel0(), new Constraints(new Leading(242, 10, 10), new Leading(12, 12, 12); add(getJLabel4(), new Constraints(new Leading(32, 10, 10), new Leading(388, 10, 10); add(getJLabel2(), new Constraints(new Lea

7、ding(26, 12, 12), new Leading(231, 19, 10, 10); add(getJTextField2(), new Constraints(new Leading(234, 131, 12, 12), new Leading(385, 28, 10, 10); add(getJLabel1(), new Constraints(new Leading(26, 168, 12, 12), new Leading(46, 25, 10, 10); add(getJLabel3(), new Constraints(new Leading(30, 10, 10), n

8、ew Leading(326, 12, 12); add(getJButton0(), new Constraints(new Leading(434, 10, 10), new Leading(325, 12, 12); add(getJScrollPane0(), new Constraints(new Leading(238, 200, 10, 10), new Leading(66, 150, 12, 12); add(getJTextField1(), new Constraints(new Leading(234, 130, 12, 12), new Leading(325, 30

9、, 12, 12); add(getJTextField0(), new Constraints(new Leading(234, 130, 12, 12), new Leading(264, 29, 10, 10); add(getJButton1(), new Constraints(new Leading(431, 10, 10), new Leading(262, 12, 12); setSize(641, 459); private JButton getJButton1() if (jButton1 = null) jButton1 = new JButton(); jButton

10、1.setText(确定); jButton1.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) double a = getA(x, y); double b = getB(x, y, a); String A = String.format(%.2f, a); String B = String.format(%.2f, b); String S = y= + A + * + x + + + B; jTextField0.setText(String.valueOf(S

11、); ); return jButton1; public static double getA( double x , double y ) int n = x.length ; return ( n * pSum( x , y ) - sum( x ) * sum( y ) ) / ( n * sqSum( x ) - Math.pow(sum(x), 2) ) ; /* * 计算常量系数 * param x * param y * param a * return */ public static double getB( double x , double y , double a )

12、 int n = x.length ; return sum( y ) / n - a * sum( x ) / n ; private static double sum(double c ) double s = 0 ; for( int i=0;ic.length;i+ ) s = s + ci ; return s ; private static double sqSum(double c ) double s = 0 ; for( int i=0;ic.length;i+) s = s + Math.pow(ci, 2) ; return s ; private static do

13、uble pSum( double x , double y ) double s = 0 ; for( int i = 0 ; i x.length ; i+ ) s = s + xi * yi ; return s ; private JLabel getJLabel2() if (jLabel2 = null) jLabel2 = new JLabel(); jLabel2.setText(根据最小二乘法计算得到预测方程为:); return jLabel2; private JTextField getJTextField0() if (jTextField0 = null) jTex

14、tField0 = new JTextField(); return jTextField0; private JButton getJButton0() if (jButton0 = null) jButton0 = new JButton(); jButton0.setText(预测); jButton0.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) z=Integer.parseInt(jTextField1.g

15、etText(); double a = getA( x , y ) ; double b = getB( x , y , a ) ; String A = String.format(%.2f, a); String B = String.format(%.2f, b); double m= a * z + b ; String M = String.format(%.2f, m); jTextField2.setText(String.valueOf(M); ); return jButton0; private JTextField getJTextField2() if (jTextF

16、ield2 = null) jTextField2 = new JTextField(); return jTextField2; private JTextField getJTextField1() if (jTextField1 = null) jTextField1 = new JTextField(); return jTextField1; private JLabel getJLabel3() if (jLabel3 = null) jLabel3 = new JLabel(); jLabel3.setText(输入某位学生的期中成绩:); return jLabel3; pri

17、vate JLabel getJLabel4() if (jLabel4 = null) jLabel4 = new JLabel(); jLabel4.setText(该学生期末成绩预测值为:); return jLabel4; private JLabel getJLabel1() if (jLabel1 = null) jLabel1 = new JLabel(); jLabel1.setText(课程数据库中的学生成绩:); return jLabel1; private JScrollPane getJScrollPane0() if (jScrollPane0 = null) jS

18、crollPane0 = new JScrollPane(); jScrollPane0.setViewportView(getJTable0(); return jScrollPane0; private JTable getJTable0() if (jTable0 = null) jTable0 = new JTable(); jTable0.setModel(new DefaultTableModel(new Object 72, 84, , 50, 63, , 81, 77, , 74, 78, , 94, 90, , 86, 75, , 59, 49, , 83, 79, , 65

19、, 77, , 33, 52, , 88, 74, , 81, 90, , , new String 期中成绩X, 期末成绩Y, ) private static final long serialVersionUID = 1L; Class types = new Class Object.class, Object.class, ; public Class getColumnClass(int columnIndex) return typescolumnIndex; ); return jTable0; private JLabel getJLabel0() if (jLabel0 =

20、 null) jLabel0 = new JLabel(); jLabel0.setText(最小二乘法预测学生期末成绩); return jLabel0; private static void installLnF() try String lnfClassname = PREFERRED_LOOK_AND_FEEL; if (lnfClassname = null) lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName(); UIManager.setLookAndFeel(lnfClassname); catch (

21、Exception e) System.err.println(Cannot install + PREFERRED_LOOK_AND_FEEL + on this platform: + e.getMessage(); public static void main(String args) installLnF(); SwingUtilities.invokeLater(new Runnable() Override public void run() window frame = new window(); frame.setDefaultCloseOperation(window.EX

22、IT_ON_CLOSE); frame.setTitle(window); frame.getContentPane().setPreferredSize(frame.getSize(); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); );5程序实现初始运行界面:输入一期中成绩,点击预测:如输入期中成绩89,执行为:6实验总结:通过这次实验,我更加深入的了解了最小二乘法的运算过程,结合着java编程语言,把整个最小二乘法表达出来。在实验过程中运用了窗体,使得人机交互变得更加简洁、方便,也顺便复习了一下窗体的相关知识。当然在实验过程中也发现了自己的不足,因为学习的知识有限,没能画出一元线性图形来,不过希望在以后的学习可以更加完善自己,争取把程序做的更加完善。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1