什么是"UserWarning: No features were selected"



我正在使用lassocv((模型进行特征选择。它给了我这个问题,也没有选择任何功能。" C: USER XYZ ANACONDA3 lib lib site-packages sklearn feature_selection base.py.py:80:userWarning:未选择功能:数据太嘈杂或选择测试太严格了。 用户保证("

代码在下面给出。

数据在https://www.kaggle.com/jtrofe/beer-recipes/downloads/recipedata.csv/3

import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
from sklearn.feature_selection import SelectFromModel
from sklearn.linear_model import LassoCV
# dataset URL = https://www.kaggle.com/jtrofe/beer-recipes/downloads/recipeData.csv/3
dataframe = pd.read_csv('Brewer Friend Beer Recipes.csv', encoding = 'latin')
# Encoding the non numerical columns
def encoding_data(dataframe):
    if(dataframe.dtype == 'object'):
        return LabelEncoder().fit_transform(dataframe.astype(str))
    else:
        return dataframe
# Feature Selection using the selected Target Feature
def feature_selection(raw_dataframe, target_feature_list):
    output_list = []
    # preprocessing Converting Categorical data into Numeric Data
    dataframe = raw_dataframe.apply(encoding_data)
    column_list = dataframe.columns.tolist()
    dataframe = dataframe.dropna()
    for target in target_feature_list:
        target_feature = target
        x = dataframe.drop(columns=[target_feature])
        y = dataframe[target_feature].values
        # Lasso feature selection 
        estimator = LassoCV(cv = 3, n_alphas = 1)
        featureselection = SelectFromModel(estimator)
        featureselection.fit(x,y)
        features = featureselection.transform(x)
        feature_list = x.columns[featureselection.get_support()]
        features = ''
        features = ', '.join(feature_list)
        l = (target,features)
        output_list.append(l)
    output_df = pd.DataFrame(output_list,columns = ['Name','Selected Features'])
    print('nThe Feature Selection is done with the respective target feature(s)')
    return output_df
print(feature_selection(dataframe, ['BrewMethod']))

我会收到此警告,并且没有选择功能。

"C:UsersxyzAnaconda3libsite-packagessklearnfeature_selectionbase.py:80: UserWarning: No features were selected: either the data is too noisy or the selection test too strict. UserWarning)"

任何想法如何纠正这一点?

如果未选择功能,则可以逐渐降低lambda(或在Scikit的案例alpha中(。这将减少惩罚,并可能返回一些非零系数。

尚未选择系数非常不寻常。您应该考虑检查数据中的相关性。也许您有很多共线性。

相关内容

  • 没有找到相关文章

最新更新