【问题标题】:Multiple Object variable to numeric?多个对象变量为数字?
【发布时间】:2020-04-14 07:28:55
【问题描述】:

我有一个非常大的数据集,我必须在其中创建一个决策树。为此,我需要进行拟合,并且不能拥有对象变量。我有 20 个对象变量。如何将它们转换为数字? 在python中

['MachineIdentifier',
 'ProductName',
 'EngineVersion',
 'AppVersion',
 'AvSigVersion',
 'Platform',
 'Processor',
 'OsVer',
 'OsPlatformSubRelease',
 'OsBuildLab',
 'SkuEdition',
 'SmartScreen',
 'Census_MDC2FormFactor',
 'Census_DeviceFamily',
 'Census_ProcessorClass',
 'Census_PrimaryDiskTypeName',
 'Census_ChassisTypeName',
 'Census_PowerPlatformRoleName',
 'Census_InternalBatteryType',
 'Census_OSVersion',
 'Census_OSArchitecture',
 'Census_OSBranch',
 'Census_OSEdition',
 'Census_OSSkuName',
 'Census_OSInstallTypeName',
 'Census_OSWUAutoUpdateOptionsName',
 'Census_GenuineStateName',
 'Census_ActivationChannel',
 'Census_FlightRing']

这些是我的变量,里面有不同的值

【问题讨论】:

  • 你应该添加你的代码以便社区可以帮助你
  • P{请不要使用 cmets 空间来提供代码 - 相应地编辑和更新您的问题,如果不再需要,请删除评论。

标签: python variables scikit-learn numeric


【解决方案1】:

你需要使用LabelEncoder():

from sklearn import preprocessing
le = preprocessing.LabelEncoder()
features = ['obj1', 'obj2', 'obj3', 'obj4']
le.fit(features)
new_features = le.transform(features)

【讨论】:

    猜你喜欢
    • 2020-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 2017-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多