【问题标题】:how do i know the performance of each categorical features我如何知道每个分类特征的性能
【发布时间】:2018-03-12 04:12:35
【问题描述】:
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)

from sklearn.linear_model import LogisticRegression
lr.fit(X_train, y_train)

print(metrics.accuracy_score(y_test, y_pred)) 

我在训练数据中使用逻辑回归构建模型我有三个特征一个特征是分类特征(例如颜色:蓝色、红色、绿色)。我转换为虚拟变量并构建模型。我想知道每种类型的表现都是绿色红色蓝色而不是整体

【问题讨论】:

    标签: python


    【解决方案1】:

    假设存储分类数据的特征在第一列,因此索引0。您可以从X_test中提取与每个类别相关的数据为

    col = 0
    for i in set(X_test[:,col]):
        ixs = X_test[:,col] == i
        print('Category ' + str(i) + ': ') 
        print(metrics.accuracy_score(X_test[ixs], y_test[ixs])) 
    

    这将为您提供第一列中每个类别的准确性。

    【讨论】:

    • 您好,感谢您的回复。我收到此错误分类指标无法处理连续多输出和二进制目标的混合
    • 能否提供其余代码和数据样本?
    • ([[ 0. , 0. , 0. , ..., -0.30519614, -0.66772746, 0.19414677]]) 。 x 有 43 列长,第 41 列属于分类特征,它们被转换为 0 和 1,y 只是 1 列,其中包含零和 1s
    猜你喜欢
    • 2020-04-19
    • 2012-10-01
    • 2021-06-19
    • 2016-08-20
    • 1970-01-01
    • 2019-06-13
    • 2021-07-27
    • 2018-07-20
    • 2023-01-15
    相关资源
    最近更新 更多