Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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 多对象变量到数值?_Python_Variables_Scikit Learn_Numeric - Fatal编程技术网

Python 多对象变量到数值?

Python 多对象变量到数值?,python,variables,scikit-learn,numeric,Python,Variables,Scikit Learn,Numeric,我有一个很大的数据集,我必须在其中做一个决策树。为此,我需要进行拟合,但不能有对象变量。我有20个对象变量。如何将它们转换为数字? 用python ['MachineIdentifier', 'ProductName', 'EngineVersion', 'AppVersion', 'AvSigVersion', 'Platform', 'Processor', 'OsVer', 'OsPlatformSubRelease', 'OsBuildLab', 'SkuEditio

我有一个很大的数据集,我必须在其中做一个决策树。为此,我需要进行拟合,但不能有对象变量。我有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']

这些是我的变量,里面有不同的值。您需要使用
LabelEncoder()


您应该添加您的代码,以便社区可以帮助您。请不要使用注释空间提供代码-相应地编辑和更新您的问题,如果不再需要,请删除注释。
from sklearn import preprocessing
le = preprocessing.LabelEncoder()
features = ['obj1', 'obj2', 'obj3', 'obj4']
le.fit(features)
new_features = le.transform(features)