Table of Contents
Reinforcement Learning: Markov Decision Problems for Feature Selection
用于特征选择与强化学习的python库
总结
Home Technology peripherals AI Feature selection via reinforcement learning strategies

Feature selection via reinforcement learning strategies

Jun 05, 2024 pm 01:00 PM
machine learning reinforcement learning

Feature selection is a key step in the process of building a machine learning model. Choosing good features for the model and the task we want to accomplish can improve performance.

Feature selection via reinforcement learning strategies

If we are dealing with high-dimensional data sets, then selecting features is particularly important. It enables the model to learn faster and better. The idea is to find the optimal number of features and the most meaningful features.

In this article, we will introduce and implement a new feature selection through reinforcement learning strategy. We start by discussing reinforcement learning, specifically Markov decision processes. It is a very new method in the field of data science, especially suitable for feature selection. Then it introduces its implementation and how to install and use the python library (FSRLearning). Finally, a simple example is used to demonstrate this process.

Reinforcement Learning: Markov Decision Problems for Feature Selection

Reinforcement learning (RL) techniques can be very effective in solving problems like game solving The problem. The concept of reinforcement learning is based on Markov Decision Process (MDP). The point here is not to get into an in-depth definition but to get a general understanding of how it works and how it can be useful for our problem. In reinforcement learning, an agent learns by interacting with its environment. It makes decisions by observing the current state and reward signals, and will receive positive or negative feedback based on the chosen action. The agent's goal is to maximize the cumulative reward by trying different actions. An important concept of reinforcement learning

The thinking behind reinforcement learning is that the agent starts from an unknown environment. Collect actions to complete the mission. The agent will be more inclined to choose some actions under the influence of its current state and previously selected actions. Each time a new state is reached and an action taken, the agent receives a reward. Here are the main parameters we need to define for feature selection:

State, action, reward, how to choose action

First, dataset A subset of the features that exist. For example, if the dataset has three features (age, gender, height) plus a label, the possible states are as follows:

[] --> Empty set [Age], [Gender], [Height] --> 1-feature set [Age, Gender], [Gender, Height], [Age, Height] --> 2-feature set [Age, Gender, Height] --> All-feature set
Copy after login

In a state, The order of the features doesn't matter, we have to think of it as a set, not a list of features.

Regarding actions, we can go from one subset to any subset of unexplored features. In a feature selection problem, the action is to select features that have not yet been explored in the current state and add them to the next state. Here are some possible moves:

[Age] -> [Age, Gender] [Gender, Height] -> [Age, Gender, Height]
Copy after login

Here is an example of an impossible move:

[Age] -> [Age, Gender, Height] [Age, Gender] -> [Age] [Gender] -> [Gender, Gender]
Copy after login

We have defined the status and action, but not the reward yet. The reward is a real number used to evaluate the quality of the state.

In feature selection problems, one possible reward is to improve the accuracy metric of the same model by adding new features. Here is an example of how the reward is calculated:

[Age] --> Accuracy = 0.65 [Age, Gender] --> Accuracy = 0.76 Reward(Gender) = 0.76 - 0.65 = 0.11
Copy after login

For each state we visit for the first time, a classifier (model) is trained using a set of features . This value is stored in the state and the corresponding classifier. The process of training the classifier is time-consuming and laborious, so we only train it once. Because the classifier does not take into account the order of features, we can treat this problem as a graph rather than a tree. In this example, the reward for selecting “gender” as a new feature for the model is the difference in accuracy between the current state and the next state.

Feature selection via reinforcement learning strategies

In the above image, each feature is mapped to a number ("Age" is 1, "Gender" is 2, "Height" is ” is 3). How do we choose the next state from the current state or how do we explore the environment?

We have to find the optimal method because if we explore all possible feature sets in a problem with 10 features, the number of states will be

10! + 2 = 3 628 802
Copy after login

这里的+2是因为考虑一个空状态和一个包含所有可能特征的状态。我们不可能在每个状态下都训练一个模型,这是不可能完成的,而且这只是有10个特征,如果有100个特征那基本上就是无解了。

但是在强化学习方法中,我们不需要在所有的状态下都去训练一个模型,我们要为这个问题确定一些停止条件,比如从当前状态随机选择下一个动作,概率为epsilon(介于0和1之间,通常在0.2左右),否则选择使函数最大化的动作。对于特征选择是每个特征对模型精度带来的奖励的平均值。

这里的贪心算法包含两个步骤:

1、以概率为epsilon,我们在当前状态的可能邻居中随机选择下一个状态

2、选择下一个状态,使添加到当前状态的特征对模型的精度贡献最大。为了减少时间复杂度,可以初始化了一个包含每个特征值的列表。每当选择一个特性时,此列表就会更新。使用以下公式,更新是非常理想的:

Feature selection via reinforcement learning strategies

AORf:特征“f”带来的奖励的平均值

K: f被选中的次数

V(F):特征集合F的状态值(为了简单描述,本文不详细介绍)

所以我们就找出哪个特征给模型带来了最高的准确性。这就是为什么我们需要浏览不同的状态,在在许多不同的环境中评估模型特征的最全局准确值。

因为目标是最小化算法访问的状态数,所以我们访问的未访问过的状态越少,需要用不同特征集训练的模型数量就越少。因为从时间和计算能力的角度来看,训练模型以获得精度是最昂贵方法,我们要尽量减少训练的次数。

最后在任何情况下,算法都会停止在最终状态(包含所有特征的集合)而我们希望避免达到这种状态,因为用它来训练模型是最昂贵的。

上面就是我们针对于特征选择的强化学习描述,下面我们将详细介绍在python中的实现。

用于特征选择与强化学习的python库

有一个python库可以让我们直接解决这个问题。但是首先我们先准备数据

我们直接使用UCI机器学习库中的数据:

#Get the pandas DataFrame from the csv file (15 features, 690 rows) australian_data = pd.read_csv('australian_data.csv', header=None)  #DataFrame with the features X = australian_data.drop(14, axis=1)  #DataFrame with the labels y = australian_data[14]
Copy after login

然后安装我们用到的库

pip install FSRLearning
Copy after login

直接导入

from FSRLearning import Feature_Selector_RL
Copy after login

Feature_Selector_RL类就可以创建一个特性选择器。我们需要以下的参数

feature_number (integer): DataFrame X中的特性数量

feature_structure (dictionary):用于图实现的字典

eps (float [0;1]):随机选择下一状态的概率,0为贪婪算法,1为随机算法

alpha (float [0;1]):控制更新速率,0表示不更新状态,1表示经常更新状态

gamma  (float[0,1]):下一状态观察的调节因子,0为近视行为状态,1为远视行为

nb_iter (int):遍历图的序列数

starting_state (" empty "或" random "):如果" empty ",则算法从空状态开始,如果" random ",则算法从图中的随机状态开始

所有参数都可以机型调节,但对于大多数问题来说,迭代大约100次就可以了,而epsilon值在0.2左右通常就足够了。起始状态对于更有效地浏览图形很有用,但它非常依赖于数据集,两个值都可以测试。

我们可以用下面的代码简单地初始化选择器:

fsrl_obj = Feature_Selector_RL(feature_number=14, nb_iter=100)
Copy after login

与大多数ML库相同,训练算法非常简单:

results = fsrl_obj.fit_predict(X, y)
Copy after login

下面是输出的一个例子:

Feature selection via reinforcement learning strategies

输出是一个5元组,如下所示:

DataFrame X中特性的索引(类似于映射)

特征被观察的次数

所有迭代后特征带来的奖励的平均值

从最不重要到最重要的特征排序(这里2是最不重要的特征,7是最重要的特征)

全局访问的状态数

还可以与Scikit-Learn的RFE选择器进行比较。它将X, y和选择器的结果作为输入。

fsrl_obj.compare_with_benchmark(X, y, results)
Copy after login

输出是在RFE和FSRLearning的全局度量的每一步选择之后的结果。它还输出模型精度的可视化比较,其中x轴表示所选特征的数量,y轴表示精度。两条水平线是每种方法的准确度中值。

Feature selection via reinforcement learning strategies

Average benchmark accuracy : 0.854251012145749, rl accuracy : 0.8674089068825909 Median benchmark accuracy : 0.8552631578947368, rl accuracy : 0.868421052631579 Probability to get a set of variable with a better metric than RFE : 1.0 Area between the two curves : 0.17105263157894512
Copy after login

可以看到RL方法总是为模型提供比RFE更好的特征集。

另一个有趣的方法是get_plot_ratio_exploration。它绘制了一个图,比较一个精确迭代序列中已经访问节点和访问节点的数量。

Feature selection via reinforcement learning strategies

由于设置了停止条件,算法的时间复杂度呈指数级降低。即使特征的数量很大,收敛性也会很快被发现。下面的图表示一定大小的集合被访问的次数。

Feature selection via reinforcement learning strategies

在所有迭代中,算法访问包含6个或更少变量的状态。在6个变量之外,我们可以看到达到的状态数量正在减少。这是一个很好的行为,因为用小的特征集训练模型比用大的特征集训练模型要快。

总结

我们可以看到RL方法对于最大化模型的度量是非常有效的。它总是很快地收敛到一个有趣的特性子集。该方法在使用FSRLearning库的ML项目中非常容易和快速地实现。

The above is the detailed content of Feature selection via reinforcement learning strategies. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

15 recommended open source free image annotation tools 15 recommended open source free image annotation tools Mar 28, 2024 pm 01:21 PM

Image annotation is the process of associating labels or descriptive information with images to give deeper meaning and explanation to the image content. This process is critical to machine learning, which helps train vision models to more accurately identify individual elements in images. By adding annotations to images, the computer can understand the semantics and context behind the images, thereby improving the ability to understand and analyze the image content. Image annotation has a wide range of applications, covering many fields, such as computer vision, natural language processing, and graph vision models. It has a wide range of applications, such as assisting vehicles in identifying obstacles on the road, and helping in the detection and diagnosis of diseases through medical image recognition. . This article mainly recommends some better open source and free image annotation tools. 1.Makesens

This article will take you to understand SHAP: model explanation for machine learning This article will take you to understand SHAP: model explanation for machine learning Jun 01, 2024 am 10:58 AM

In the fields of machine learning and data science, model interpretability has always been a focus of researchers and practitioners. With the widespread application of complex models such as deep learning and ensemble methods, understanding the model's decision-making process has become particularly important. Explainable AI|XAI helps build trust and confidence in machine learning models by increasing the transparency of the model. Improving model transparency can be achieved through methods such as the widespread use of multiple complex models, as well as the decision-making processes used to explain the models. These methods include feature importance analysis, model prediction interval estimation, local interpretability algorithms, etc. Feature importance analysis can explain the decision-making process of a model by evaluating the degree of influence of the model on the input features. Model prediction interval estimate

Transparent! An in-depth analysis of the principles of major machine learning models! Transparent! An in-depth analysis of the principles of major machine learning models! Apr 12, 2024 pm 05:55 PM

In layman’s terms, a machine learning model is a mathematical function that maps input data to a predicted output. More specifically, a machine learning model is a mathematical function that adjusts model parameters by learning from training data to minimize the error between the predicted output and the true label. There are many models in machine learning, such as logistic regression models, decision tree models, support vector machine models, etc. Each model has its applicable data types and problem types. At the same time, there are many commonalities between different models, or there is a hidden path for model evolution. Taking the connectionist perceptron as an example, by increasing the number of hidden layers of the perceptron, we can transform it into a deep neural network. If a kernel function is added to the perceptron, it can be converted into an SVM. this one

Identify overfitting and underfitting through learning curves Identify overfitting and underfitting through learning curves Apr 29, 2024 pm 06:50 PM

This article will introduce how to effectively identify overfitting and underfitting in machine learning models through learning curves. Underfitting and overfitting 1. Overfitting If a model is overtrained on the data so that it learns noise from it, then the model is said to be overfitting. An overfitted model learns every example so perfectly that it will misclassify an unseen/new example. For an overfitted model, we will get a perfect/near-perfect training set score and a terrible validation set/test score. Slightly modified: "Cause of overfitting: Use a complex model to solve a simple problem and extract noise from the data. Because a small data set as a training set may not represent the correct representation of all data." 2. Underfitting Heru

The evolution of artificial intelligence in space exploration and human settlement engineering The evolution of artificial intelligence in space exploration and human settlement engineering Apr 29, 2024 pm 03:25 PM

In the 1950s, artificial intelligence (AI) was born. That's when researchers discovered that machines could perform human-like tasks, such as thinking. Later, in the 1960s, the U.S. Department of Defense funded artificial intelligence and established laboratories for further development. Researchers are finding applications for artificial intelligence in many areas, such as space exploration and survival in extreme environments. Space exploration is the study of the universe, which covers the entire universe beyond the earth. Space is classified as an extreme environment because its conditions are different from those on Earth. To survive in space, many factors must be considered and precautions must be taken. Scientists and researchers believe that exploring space and understanding the current state of everything can help understand how the universe works and prepare for potential environmental crises

Implementing Machine Learning Algorithms in C++: Common Challenges and Solutions Implementing Machine Learning Algorithms in C++: Common Challenges and Solutions Jun 03, 2024 pm 01:25 PM

Common challenges faced by machine learning algorithms in C++ include memory management, multi-threading, performance optimization, and maintainability. Solutions include using smart pointers, modern threading libraries, SIMD instructions and third-party libraries, as well as following coding style guidelines and using automation tools. Practical cases show how to use the Eigen library to implement linear regression algorithms, effectively manage memory and use high-performance matrix operations.

Explainable AI: Explaining complex AI/ML models Explainable AI: Explaining complex AI/ML models Jun 03, 2024 pm 10:08 PM

Translator | Reviewed by Li Rui | Chonglou Artificial intelligence (AI) and machine learning (ML) models are becoming increasingly complex today, and the output produced by these models is a black box – unable to be explained to stakeholders. Explainable AI (XAI) aims to solve this problem by enabling stakeholders to understand how these models work, ensuring they understand how these models actually make decisions, and ensuring transparency in AI systems, Trust and accountability to address this issue. This article explores various explainable artificial intelligence (XAI) techniques to illustrate their underlying principles. Several reasons why explainable AI is crucial Trust and transparency: For AI systems to be widely accepted and trusted, users need to understand how decisions are made

Five schools of machine learning you don't know about Five schools of machine learning you don't know about Jun 05, 2024 pm 08:51 PM

Machine learning is an important branch of artificial intelligence that gives computers the ability to learn from data and improve their capabilities without being explicitly programmed. Machine learning has a wide range of applications in various fields, from image recognition and natural language processing to recommendation systems and fraud detection, and it is changing the way we live. There are many different methods and theories in the field of machine learning, among which the five most influential methods are called the "Five Schools of Machine Learning". The five major schools are the symbolic school, the connectionist school, the evolutionary school, the Bayesian school and the analogy school. 1. Symbolism, also known as symbolism, emphasizes the use of symbols for logical reasoning and expression of knowledge. This school of thought believes that learning is a process of reverse deduction, through existing

See all articles