how to get the labelencoder for new data in Decision Tree

686 Views Asked by At

I'm performing the Decision Tree with the help of below sample data.

enter image description here

So I've converted the above data to LabelEncoder to perform Decision Tree and successfully created a DT model.

enter image description here

So now my requirement is I would like to predict on the below values, So how to pass these values in the python code.

enter image description here

In order to predict the existing value I can use the below Predict Code.

model.predict([[2,1,1]])

COMPLETE CODE

import pandas as pd

df = pd.read_csv(r"salaries.csv")
df.head()

inputs = df.drop('salary_more_then_100k',axis='columns')
target = df['salary_more_then_100k']

from sklearn.preprocessing import LabelEncoder
le_company = LabelEncoder()
le_job = LabelEncoder()
le_degree = LabelEncoder()

inputs['company_n'] = le_company.fit_transform(inputs['company'])
inputs['job_n'] = le_job.fit_transform(inputs['job'])
inputs['degree_n'] = le_degree.fit_transform(inputs['degree'])

inputs_n = inputs.drop(['company','job','degree'],axis='columns')

from sklearn import tree
model = tree.DecisionTreeClassifier()
model.fit(inputs_n, target)

model.score(inputs_n,target)
0

There are 0 best solutions below