Python 多对象变量到数值?
我有一个很大的数据集,我必须在其中做一个决策树。为此,我需要进行拟合,但不能有对象变量。我有20个对象变量。如何将它们转换为数字? 用pythonPython 多对象变量到数值?,python,variables,scikit-learn,numeric,Python,Variables,Scikit Learn,Numeric,我有一个很大的数据集,我必须在其中做一个决策树。为此,我需要进行拟合,但不能有对象变量。我有20个对象变量。如何将它们转换为数字? 用python ['MachineIdentifier', 'ProductName', 'EngineVersion', 'AppVersion', 'AvSigVersion', 'Platform', 'Processor', 'OsVer', 'OsPlatformSubRelease', 'OsBuildLab', 'SkuEditio
['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']
这些是我的变量,里面有不同的值。您需要使用
LabelEncoder()
:
您应该添加您的代码,以便社区可以帮助您。请不要使用注释空间提供代码-相应地编辑和更新您的问题,如果不再需要,请删除注释。
from sklearn import preprocessing
le = preprocessing.LabelEncoder()
features = ['obj1', 'obj2', 'obj3', 'obj4']
le.fit(features)
new_features = le.transform(features)