Any way to get mappings of a label encoder in Python pandas?

前端 未结 8 1657
清酒与你
清酒与你 2021-02-01 15:11

I am converting strings to categorical values in my dataset using the following piece of code.

data[\'weekday\'] = pd.Categorical.from_array(data.weekday).labels         


        
8条回答
  •  遥遥无期
    2021-02-01 15:32

    Its very simple, they have a built-in function for this.

    from sklearn import preprocessing
    le = preprocessing.LabelEncoder()
    ..
    # your model steps and when you have results
    ..
    
    prediction_decoded = le.inverse_transform(prediction_encoded)
    print(prediction_decoded)
    

提交回复
热议问题