# coding=utf-8
# @Time : 2019/12/3 14:48
# @Author : Z
# @Email : S
# @File : 2.6ML_SMOTO_talentFeatures.py
#数据挖掘项目构建人才(用户)流失模型
import pandas as pd
talent_data = pd.read_csv("./train.csv")
#1.不同类型数据的整理
# 数值型数据
num_cols = ["Age", "MonthlyIncome", "NumCompaniesWorked", "PercentSalaryHike", "PerformanceRating",
"StandardHours", "TotalWorkingYears", "YearsAtCompany",
"YearsInCurrentRole", "YearsSinceLastPromotion"]
# 类别型数据
cat_cols=["Gender","MaritalStatus","OverTime"]
# 有序型数据
ord_cols=["DistanceFromHome","Education","EnvironmentSatisfaction","JobInvolvement",
"JobLevel","JobSatisfaction","RelationshipSatisfaction","StockOptionLevel",
"TrainingTimesLastYear","WorkLifeBalance"]
#类别标签
target_col=["Attrition"]
total_data=num_cols+ord_cols+cat_cols
#将所有的特征数据和类别标签进行整合
use_data=talent_data[total_data+target_col]
#2.正负样本的比例
#正负样本的不均衡问题
neg_data = use_data[use_data["Attrition"] == 0] #未离职
pos_data = use_data[use_data["Attrition"] == 1] #离职
print("正负样本比例:", len(pos_data)/len(neg_data))
print("离职:",len(pos_data))
print("未离职:",len(neg_data))
#3.数据集的切分
# X=talent_data[total_data]
# y=talent_data["Attrition"]
# from sklearn.cross_validation import train_test_split
# X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=22
数据挖掘项目构建人才(用户)流失模型
最新推荐文章于 2020-06-20 15:43:11 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)