根据SVR(support vector 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

feature Scaling:

1、从常识来看salary跟position是基本没关系,去除position这一列

2、level与salary之间数值差异很大,需要feature Scaling:具体处理方式这里使用sklearn.preprocessing 中的StandardScaler预处理level、salary这两列。当模型训练好之后,使用模型预测某个具体level的salary。最后需要进行Scaling的逆操作——inverse_transform(predicd_value)

fitting SVR to the dataset:

sklearn.svm中的SVR

regressor=SVR(kernel='rbf')

regressor.fit(x,y)

进行预测,predict_value=regressor.predict(6.5)

之后可以使用画图工具展示真实值与预测值对比图,使用 matplotlib.pyplot 

import matplotlib.pyplot as plt

plt.scatter(x,y,color='red')

plt.plot(x,regressor.predict(x),clolor='blue')

plt.title('Truth or Bluff(SVR)')

plt.xlabel('Position level')

plt.ylable('Salary')

pit.show()

运行结果:


另一种绘图方式:

import numpy as np

x_grid=np.arange(min(x),max(x),0.01)    // 起始值是min(x),结束值max(x),步长0.01

x_grid=x_grid.reshape(len(x_grid),1)    //形成一个len(x_grid)行1列的matrix

plt.scatter(x,y,color='red')

plt.plot(x_grid,regressor.predict(x_grid),color='blue')

这种绘图方式,用于预测的点增多,从而blue这条预测线更加平滑smoother curve!



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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值