我是靠谱客的博主 大力羊,最近开发中收集的这篇文章主要介绍用python实现BP神经网络预测运动员的跳高成绩,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

利用前14位运动员的运动成绩为训练样本,预测第15为运动员的跳高成绩。具体数据如下:

序号跳高成绩()30行进跑(s)立定三级跳远()助跑摸高()助跑4—6步跳高()负重深蹲杠铃()杠铃半蹲系数100(s)抓举()
12.243.29.63.452.151402.811.050
22.333.210.33.752.21203.410.970
32.243.09.03.52.21403.511.450
42.323.210.33.652.21502.810.880
52.23.210.13.52801.511.350
62.273.410.03.42.151303.211.560
72.23.29.63.552.11303.511.865
82.263.09.03.52.11001.811.340
92.23.29.63.552.11303.511.865
102.243.29.23.52.11402.511.050
112.243.29.53.42.151152.811.950
122.23.99.03.12.0802.213.050
132.23.19.53.62.1902.711.170
142.353.29.73.452.151304.610.8570
153.09.33.32.051002.811.250

程序代码如下:

import numpy as np
import scipy.special as sp
class net:
    def __init__(self, sample_data, output_data, hidden_num1,error=0.001, rate=0.8):
        sample_num, input_num = np.shape(sample_data)
        self.sample_data = sample_data  ##每个选手的各项成绩作为一行
        self.output_data = output_data
        self.sample_num = sample_num
        self.input_num = input_num
        self.hidden_num1 = hidden_num1
        self.rate = rate
        self.error = error

        self.max_data = max(self.output_data)
        self.min_data = min(self.output_data)
        self.output_data = (self.output_data-self.min_data)/(self.max_data-self.min_data)


        ##初始化权重矩阵
        self.w1 = np.random.rand(hidden_num1, input_num) * 2 - 1
        self.w2 = np.random.rand(hidden_num2, hidden_num1) * 2 - 1
        self.w3 = np.random.rand(1, hidden_num2) * 2 - 1

        self.b1 = np.random.rand(hidden_num1, 1) * 2 - 1
        self.b2 = np.random.rand(hidden_num2, 1) * 2 - 1
        self.b3 = np.random.rand(1,1) * 2 - 1

        self.train()

    def train(self):
        for i in range(self.sample_num):
            input_data = self.sample_data[i]
            lable  = self.output_data[i]
            input_data = input_data.reshape(self.input_num,1)
            lable = lable.reshape(1,1)

            input_hidden1 = np.dot(self.w1, input_data)+self.b1
            output_hidden1 = sp.expit(input_hidden1)
            output_hidden1 = output_hidden1.reshape(hidden_num1,1)
            input_hidden2 = np.dot(self.w2, output_hidden1)+self.b2
            output_hidden2 = sp.expit(input_hidden2)
            output_hidden2 = output_hidden2.reshape(hidden_num2, 1)
            input_out = np.dot(self.w3, output_hidden2)+self.b3
            final = sp.expit(input_out)

            E3 = final * (1 - final) * (lable - final)

            while (abs(E3) >= self.error):
                E2 = output_hidden2*(1-output_hidden2)*np.dot(self.w3.T,E3)
                E1 = output_hidden1*(1-output_hidden1)*np.dot(self.w2.T,E2)

                self.w1 += self.rate * E1 * input_data.T
                self.w2 += self.rate * E2 * output_hidden1.T
                self.w3 += self.rate * E3 * output_hidden2.T

                self.b1 += self.rate * E1
                self.b2 += self.rate * E2
                self.b3 += self.rate * E3

                input_hidden1 = np.dot(self.w1, input_data)+self.b1
                output_hidden1 = sp.expit(input_hidden1)
                output_hidden1 = output_hidden1.reshape(hidden_num1, 1)
                input_hidden2 = np.dot(self.w2, output_hidden1)+self.b2
                output_hidden2 = sp.expit(input_hidden2)
                output_hidden2 = output_hidden2.reshape(hidden_num2, 1)
                input_out = np.dot(self.w3, output_hidden2)+self.b3
                final = sp.expit(input_out)
                E3 = final * (1 - final) * (lable - final)

        print('finish train!')


    def privite(self, privite_data):
        privite_data = privite_data.reshape(self.input_num, 1)
        input_hidden1 = np.dot(self.w1, privite_data)+self.b1
        output_hidden1 = sp.expit(input_hidden1)
        output_hidden1 = output_hidden1.reshape(hidden_num1, 1)
        input_hidden2 = np.dot(self.w2, output_hidden1)+self.b2
        output_hidden2 = sp.expit(input_hidden2)
        output_hidden2 = output_hidden2.reshape(hidden_num2, 1)
        input_out = np.dot(self.w3, output_hidden2)+self.b3
        final = sp.expit(input_out)
        return (final*(self.max_data-self.min_data)+self.min_data)


sample_data =np.array([[3.2, 9.6, 3.45,2.15, 140,  2.8,11, 50 ],
 [  3.2,10.3, 3.75,2.2  ,120,  3.4,10.9,70 ],
 [  3,  9,  3.5, 2.2  ,140,  3.5,11.4,50 ],
 [  3.2,10.3, 3.65,2.2 , 150,  2.8,10.8,80 ],
 [  3.2,10.1, 3.5, 2, 80,  1.5,11.3,50 ],
 [  3.4,10,  3.4, 2.15, 130,  3.2,11.5,60 ],
 [  3.2, 9.6, 3.55,2.1, 130,  3.5,11.8,65 ],
 [  3,  9,  3.5, 2.1,  100,  1.8,11.3,40 ],
 [  3.2, 9.6, 3.55,2.1 , 130,  3.5,11.8,65 ],
 [  3.2, 9.2, 3.5, 2.1 , 140,  2.5,11, 50 ],
 [  3.2, 9.5, 3.4, 2.15, 115,  2.8,11.9,50 ],
 [  3.9, 9,  3.1, 2, 80,  2.2,13, 50 ],
 [  3.1, 9.5, 3.6, 2.1,90,  2.7,11.1,70 ],
 [  3.2, 9.7, 3.45,2.15, 130,  4.6,10.85 , 70 ]])
output_data = np.array([[2.24],[ 2.33],[2.24] , [2.32], [2.2], [2.27], [2.2], [2.26], [2.2], [2.24], [2.24], [2.2], [2.2], [2.35]])

hidden_num1 = 2
hidden_num2 = 1
a = net(sample_data,output_data,hidden_num1,hidden_num2)
privite_data = np.array([3.0,9.3,3.3,2.05,100,2.8,11.2,50])
y = a.privite(privite_data)
print("预测得到的跳高成绩为:",y[0][0])

运行结果如下:
在这里插入图片描述

最后

以上就是大力羊为你收集整理的用python实现BP神经网络预测运动员的跳高成绩的全部内容,希望文章能够帮你解决用python实现BP神经网络预测运动员的跳高成绩所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部