Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取除值之外的功能名称-SciKitLearn+Pandas_Python_Csv_Pandas_Machine Learning_Scikit Learn - Fatal编程技术网

Python 获取除值之外的功能名称-SciKitLearn+Pandas

Python 获取除值之外的功能名称-SciKitLearn+Pandas,python,csv,pandas,machine-learning,scikit-learn,Python,Csv,Pandas,Machine Learning,Scikit Learn,我为输入生成一组功能,并使用pandas和CSV格式将其存储为表。 每个列标题表示要素名称,但第一个空白列除外,空白列是存储每行的类标签的位置 我的下一步是将表从csv文件读入scikit学习。我现在又在用熊猫做这件事了。但是,在使用不同的特征选择方法和不同的初始生成特征对我的模型进行训练和实验后,我需要所选特征的名称。 我认为这应该是微不足道的,但我只是没有找到如何做到这一点。 注意:我不处理标准文本文档,因此CountVectorizer和NaiveBayes/nltk等对我没有帮助。 我需

我为输入生成一组功能,并使用pandas和CSV格式将其存储为表。 每个列标题表示要素名称,但第一个空白列除外,空白列是存储每行的类标签的位置

我的下一步是将表从csv文件读入scikit学习。我现在又在用熊猫做这件事了。但是,在使用不同的特征选择方法和不同的初始生成特征对我的模型进行训练和实验后,我需要所选特征的名称。 我认为这应该是微不足道的,但我只是没有找到如何做到这一点。 注意:我不处理标准文本文档,因此CountVectorizer和NaiveBayes/nltk等对我没有帮助。 我需要一种方法来获取选定的特性,最好是删除未选定的特性,以便在新的测试数据上应用模型和选定的特性

多谢各位

我的数据当前加载方式如下:

import numpy as np
import pandas as pd
from sklearn.preprocessing import LabelEncoder, LabelBinarizer

def load_data(filename="Feat_normalized.csv") :
    df = pd.read_csv(filename, index_col=0)
    lb = LabelEncoder()
    labels = lb.fit_transform((df.index.values))
    features = df.values
    feature_names = list(df.columns)
    feature_names.pop(0)  #Remove index.
    return (features, labels, lb)

features, labels, lb_encoder = load_data(filename)
X, y = features, labels

clf_logit = LogisticRegression(penalty="l1", dual=False, class_weight='auto')
X_reduced = clf_logit.fit_transform(X, y)
print('New sparse (filtered) features matrix size:')
print(X_svm.shape)

#Then fit to various models, Random forests, SVM, etc'.. 
输入数据/csv中前两行的截断示例:

            AA_C    AA__D   AA__E   AA_F    AA__G   AA_H    AA_I    AA_K    AA_L    AA_M
Mammal_sequence_1.0.fasta   3.838099345 0.456591162 3.764884604 3.620232638 3.460992571 3.858487012 2.69247235  3.18710619  3.671029774 4.625996297 1.542632799
AA=特征名称。哺乳动物_序列_1.0.fasta=类名/标签;每行1个,标题为空

多谢各位