Decision Tree Regression帮助HR评估新员工的薪资区间

我所理解decision tree的切入点是两张图:


这两张图表示的意思是一样的,都是将已有的数据归类。

预测使用的数据:

Position,Level,Salary
Business Analyst,1,45000
Junior Consultant,2,50000
Senior Consultant,3,60000
Manager,4,80000
Country Manager,5,110000
Region Manager,6,150000
Partner,7,200000
Senior Partner,8,300000
C-level,9,500000

CEO,10,1000000

预测python代码:

# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
#Importing the dataset
dataset=pd.read_csv('Position_Salaries.csv')
x=dataset.iloc[:,1:2].values
y=dataset.iloc[:,2].values


#Fitting Decision Tree Regression to the dataset
from sklearn.tree import DecisionTreeRegressor 
regressor=DecisionTreeRegressor(random_state=0)
regressor.fit(x,y)


#Predicting a new result
y_pred=regressor.predict(6.5)


# Visualising the Decision Tree Regression results(higher resolution)
x_grid=np.arange(min(x),max(x),0.1)
x_grid=x_grid.reshape(len(x_grid),1)
plt.scatter(x,y,color='red')
plt.plot(x_grid,regressor.predict(x_grid),color='blue')
plt.title('Truth or Bluff(Decision Tree Regression)')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()

结果

困惑点:DecisionTreeRegressor(random_state=0)内部的是实现方式不清楚!三人行,必有我师焉,望能从大家的留言中得到进一步的答案,谢谢。

王家林老师人工智能AI第10课 老师微信13928463918

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章