Classifying our own excel data using radial basis function (RBF) neural networks --- Detailed python code included, RBFRegressor

Insert image description here



1. What is Radial Basis Function Neural Network?

  1. Radial Basis Function Neural Network is an artificial neural network that consists of three layers: input layer, hidden layer and output layer. Unlike traditional neural networks, radial basis neural networks do not use traditional activation functions, but use radial basis functions as activation functions, that is: y = f ( z ) y = f(z)y=f ( z ) , wherefff is the radial basis function,zzz is the input signal.

  2. Radial basis functions usually use functions such as Gaussian (radial gaussian), polynomial (radial polynomial) and Thin Plate Splines (radial Thin Plate Splines). When training, the network learns using a set of known samples to determine appropriate weight values. After training, the network is able to map the input to an output that is a continuous function, making it suitable for regression and classification problems.
  3. Regarding the above data, the radial basis neural network can perform binary classification. In this data set, the sample labels are all 0. Therefore, you need to collect more labeled data, and the labels should contain two different values, such as 0 and 1, in order to use this network for binary classification. You can then use the labels as the output of the network and the input data as the input to the network for training and prediction.

2. Radial basis function (RBF) neural network to classify our own excel data - including detailed python code

We can solve this binary classification problem using the Radial Basis Function (RBF) neural network from the scikit-learn library in Python . Here is our code:

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.neural_network import RBFRegressor

# 读取Excel文件
data = pd.read_excel('data.xlsx')

# 分离数据和标签
X = data.iloc[:, 0].values.reshape(-1, 1)  # 将数据转化为二维数组
y = data.iloc[:, 1].values

# 将数据拆分为训练和测试
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

# 构建 RBF 神经网络模型,并对其进行训练
rbf = RBFRegressor(n_hidden=10)  # 设定 RBF 神经网络的隐藏层节点数为 10
rbf.fit(X_train, y_train)

# 在测试集上评估模型性能
y_pred = rbf.predict(X_test)
accuracy = np.mean((y_pred > 0.5) == y_test)
print('Accuracy:', accuracy)

Summarize

In the above code, we first use the pandas library to read the Excel file provided by you. Then, we separate the data and labels and convert the data into a 2D array. Next, we use train_test_splita function to split the data into training and test sets. We used RBFRegressorthe class to build an RBF neural network model with 10 hidden layer nodes and fit it to the training data. Finally, we evaluate the performance of the trained model on the test set and print out the accuracy of the model.

Guess you like

Origin blog.csdn.net/qlkaicx/article/details/131321455