Machine Learning 简明教程

Machine Learning - Missing Values Ratio

缺失值比率是一项机器学习功能选择技术,用于识别和去除数据集中缺失值比例过高的特征。此技术通过减少用于训练模型的特征数量并避免由于缺失值导致的偏差问题来提高模型的性能。

Missing Values Ratio is a feature selection technique used in machine learning to identify and remove features from the dataset that have a high percentage of missing values. This technique is used to improve the performance of the model by reducing the number of features used for training the model and to avoid the problem of bias caused by missing values.

缺失值比率通过计算数据集中每个特征的缺失值百分比并去除缺失值百分比高于某个阈值的特征来起作用。这样做是因为缺失值百分比过高的特征可能对预测目标变量没有帮助,并且可能使模型产生偏差。

The Missing Values Ratio works by computing the percentage of missing values for each feature in the dataset and removing the features that have a missing value percentage above a certain threshold. This is done because features with a high percentage of missing values may not be useful for predicting the target variable and can introduce bias into the model.

实施缺失值比率的步骤如下 −

The steps involved in implementing Missing Values Ratio are as follows −

  1. Compute the percentage of missing values for each feature in the dataset.

  2. Set a threshold for the percentage of missing values for the features.

  3. Remove the features that have a missing value percentage above the threshold.

  4. Use the remaining features for training the machine learning model.

Example

以下是如何在 Python 中实现缺失值比率的示例 −

Here is an example of how you can implement Missing Values Ratio in Python −

# Importing the necessary libraries
import numpy as np

# Load the diabetes dataset
diabetes = np.genfromtxt(r'C:\Users\Leekha\Desktop\diabetes.csv', delimiter=',')

# Define the predictor variables (X) and the target variable (y)
X = diabetes[:, :-1]
y = diabetes[:, -1]

# Compute the percentage of missing values for each feature
missing_percentages = np.isnan(X).mean(axis=0)

# Set the threshold for the percentage of missing values for the features
threshold = 0.5

# Find the indices of the features with a missing value percentage
# above the threshold
high_missing_indices = [i for i, percentage in enumerate(missing_percentages) if percentage > threshold]

# Remove the high missing value features from the dataset
X_filtered = np.delete(X, high_missing_indices, axis=1)

# Print the shape of the filtered dataset
print('Shape of the filtered dataset:', X_filtered.shape)

以上代码对糖尿病数据集执行缺失值比率,并去除缺失值百分比高于阈值的特征。

The above code performs Missing Values Ratio on the diabetes dataset and removes the features that have a missing value percentage above the threshold.

Output

执行此代码时,将生成以下输出 −

When you execute this code, it will produce the following output −

Shape of the filtered dataset: (769, 8)

Advantages of Missing Value Ratio

使用缺失值比率的优点如下 −

Following are the advantages of using Missing Value Ratio −

  1. Saves computational resources − With fewer features, the computational resources required to train machine learning models are reduced.

  2. Improves model performance − By removing features with a high percentage of missing values, the Missing Value Ratio can improve the performance of machine learning models.

  3. Simplifies the model − With fewer features, the model can be easier to interpret and understand.

  4. Reduces bias − By removing features with a high percentage of missing values, the Missing Value Ratio can reduce bias in the model.

Disadvantages of Missing Value Ratio

使用缺失值比率的缺点如下 −

Following are the disadvantages of using Missing Value Ratio −

  1. Information loss − The Missing Value Ratio can lead to information loss because it removes features that may contain important information.

  2. Affects non-missing data − Removing features with a high percentage of missing values can sometimes have a negative impact on non-missing data, particularly if the features are important for predicting the dependent variable.

  3. Impact on the dependent variable − Removing features with a high percentage of missing values can sometimes have a negative impact on the dependent variable, particularly if the features are important for predicting the dependent variable.

  4. Selection bias − The Missing Value Ratio may introduce selection bias if it removes features that are important for predicting the dependent variable.