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

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

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

预测使用的数据:

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()

结果

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

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

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

相关文章:

  • 2022-12-23
  • 2021-08-17
  • 2021-12-05
  • 2021-08-15
  • 2021-10-20
  • 2021-08-13
猜你喜欢
  • 2021-08-31
  • 2021-04-02
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-04-22
  • 2021-07-17
相关资源
相似解决方案