直接从数据集中提取特征名称

数据挖掘 机器学习 Python 数据集
2022-03-04 11:26:52

我想使用下面的代码可视化我的功能。但是,我收到一个错误,即我的功能被识别为“nan”而不是它们的实际名称。

而不是下面Feature = [and then writing the features that I want],我正在分配 feature = data [0,1:]这是我的数据中包含特征的第一行。我有许多不想写成字符串但只想直接从数据文件中提取的功能。我怎样才能做到这一点并获取功能的名称而不是“nan”?

# Load the dataset
data = load_data('credit')

# Specify the features of interest
features = [
        'limit', 'sex', 'edu', 'married', 'age', 'apr_delay', 'may_delay',
        'jun_delay', 'jul_delay', 'aug_delay', 'sep_delay', 'apr_bill', 'may_bill',
        'jun_bill', 'jul_bill', 'aug_bill', 'sep_bill', 'apr_pay', 'may_pay', 'jun_pay',
        'jul_pay', 'aug_pay', 'sep_pay',
    ]

# Extract the instances and target
X = data[features]
y = data.default


from yellowbrick.features import Rank1D

# Instantiate the 1D visualizer with the Sharpiro ranking algorithm
visualizer = Rank1D(features=features, algorithm='shapiro')

visualizer.fit(X, y)                # Fit the data to the visualizer
visualizer.transform(X)             # Transform the data
visualizer.poof()                   # Draw/show/poof the data
1个回答

如果您正在阅读 csv,请尝试;

data = pd.read_csv('filepath', header=None)

然后你可以做你正在做的事情来从第一行读取特征