Python实现极限学习机ELM【hpelm库】(内涵源代码)
💖作者简介:大家好,我是车神哥,府学路18号的车神🥇
⚡About—>车神:从寝室到实验室最快3分钟,最慢3分半(那半分钟其实是等红绿灯)
📝个人主页:应无所住而生其心的博客_府学路18号车神_CSDN博客
🎉点赞➕评论➕收藏 == 养成习惯(一键三连)😋⚡希望大家多多支持🤗~一起加油 😁
一直以为没有人做极限学习机的库,知道发现了hpelm库,才发现,针不戳!!!
文末Python源代码自取!!!
ELM简介
在2004年,由南洋理工学院黄广斌教授所提出的极限学习机器(Extreme Learning Machine,ELM)理论可以改善这种情况。最初的极限学习机是对单隐层前馈神经网络(single-hidden layer feed-forward neural networks,SLFNs)提出的一种新型的学习算法。它随机选取输入权重,并分析以决定网络的输出权重。在这个理论中,这种算法试图在学习速度上提供极限的性能。
ELM的优势
ELM算法和神经网络算法我认为最大的区别在于:ELM不需要进行迭代,而是一次性通过标签计算出最后一层神经元的权重。而神经网络是通过梯度下降的方法,不断的根据loss值更新权重值。
因此ELM算法不适合构造出更深的网络结构,但是减少了计算量,少了机器开销。而DELM相对于ELM加入了正则项的限制,防止过拟合。
ELM原理
ELM是一种新型的快速学习算法,对于单隐层神经网络,ELM 可以随机初始化输入权重和偏置并得到相应的隐节点输出:
导入库
直接在PyCharm终端输入:
pip install hpelm
ELM线性回归Regression
以线性回归Regression为例,Python代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/12/27 11:02
# @Author : 府学路18号车神
# @Email :yurz_control@163.com
# @File : elm_regression.py
#Import libraries
import hpelm
from keras.datasets import mnist
from keras.utils import to_categorical
import numpy as np
from numpy import random
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import time
import matplotlib.pyplot as plt
#Lists to store results
Train_T = []
Test_E = []
##Load wine testing UCI data data
data = np.genfromtxt('winequality-white.csv', dtype = float, delimiter = ';')
#Delete heading
data = np.delete(data,0,0)
x = data[:,:11]
y = data[:,-1]
#Train test split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33,random_state=42)
#===============================================================
def calculateE(y,t):
#Calculate RMSE
return mean_squared_error(y, t)
#===============================================================
#Initialization
Lmax = 40
L = 0
E = 0
ExpectedAccuracy = 0
while L < Lmax and E >= ExpectedAccuracy:
#Increase Node
L = L + 1
#Calculate Random weights, they are already addded into model using hpelm library
w = random.rand(11,L)
#Initialize model
model = hpelm.ELM(11,1)
model.add_neurons(L,'sigm')
start_time = time.time()
#Train model
model.train(x_train,y_train,'r')
Train_T.append(time.time() - start_time)
#Calculate output weights and intermediate layer
BL_HL = model.predict(x_test)
#Calculate new EMSE
E = calculateE(y_test,BL_HL)
Test_E.append(E)
#Print result
print("Hidden Node",L,"RMSE :",E)
#===================================================================
#Find best RMSE
L = Test_E.index(min(Test_E)) + 1
print()
print()
print()
print()
#Define model
model = hpelm.ELM(11,1)
model.add_neurons(L,'sigm')
start_time = time.time()
model.train(x_train,y_train,'r')
print('Training Time :',time.time() - start_time)
start_time = time.time()
BL_HL = model.predict(x_train)
print('Testing Time :',time.time() - start_time)
#Calculate training RMSE
E = calculateE(y_train,BL_HL)
print('Training RMSE :',E)
print('Testing RMSE :',min(Test_E))
#===================================================================
#Plot Data
plt.subplot(1, 2, 1) #Generate graph for ANN
plt.plot(range(1,Lmax+1),Test_E)
plt.title('Testing RMSE')
plt.xlabel('Number of Neurons in hidden layer')
plt.ylabel('Testing RMSE')
plt.subplot(1, 2, 2) #Generate graph for CNN
plt.plot(range(1,Lmax+1),Train_T)
plt.title('Training Time')
plt.xlabel('Number of Neurons in hidden layer')
plt.ylabel('Training Time')
plt.show()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
源代码
源代码及文件在这里:Python极限学习机ELM实现线性回归
链接:https://pan.baidu.com/s/1b3yTQp5El-aNwvOT7vad-A
提取码:yyds

❤坚持读Paper,坚持做笔记,坚持学习,坚持刷力扣LeetCode❤!!!
坚持刷题!!!打天梯!!!
⚡To Be No.1⚡⚡哈哈哈哈
⚡创作不易⚡,过路能❤关注、收藏、点个赞❤三连就最好不过了
ღ( ´・ᴗ・` )
❤
『
日色欲尽花含烟,月明欲素愁不眠。
』
文章来源: blog.csdn.net,作者:府学路18号车神,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/weixin_44333889/article/details/122171575
- 点赞
- 收藏
- 关注作者
评论(0)