在这些中,您基本上是在尝试预测大学GPA,大学排名等是否对试用期后被雇用或解雇有任何显着影响。基本上它是二进制分类问题(有关这些Binary Classification Best Tutorial 的完整教程)。
@janu777 给出的方法是正确的,我想在其中添加一些额外的信息。
解决这些问题的步骤是,
Data Exploration(include variable identifications)
Data Cleaning
Feature Engineering(Watching correlations kind of property among features)
Model Building and Training
Doing Predictions
基本上从 python 方面你将使用这些库
Pandas
Scikit Learn
Matplotlib
numpy
Sklearn
Statsmodelapi
数据探索:
首先,您应该将前几年的数据(以前的员工是被雇用还是被解雇)作为训练集。
import pandas as pd
import numpy as np
import matplotlib as plt
df = pd.read_csv("../trainset.csv") #Reading the dataset in a dataframe
df.describe()
数据清理
现在在这些阶段你应该看到缺失值和所有数据,你可以根据你的选择进行处理,最著名的是删除所有缺失值,这样你就可以使用这些了,
df.dropna(axis=0, how='all')
我假设您的训练集有 3 个变量,其中大学 GPA 和大学排名是特征变量。并且您的目标变量是hired/fired(1 or 0)。您应该使用预测变量和目标变量之间的相关性,并且可视化也会有所帮助。
trainingdata['GPA'].astype('float64').corr(trainingdata['target'].astype('float64'))
或
# importing the required module
import matplotlib.pyplot as plt
# x axis values
x = [1,2,3] # your feature variable
# corresponding y axis values
y = [2,4,1] # your target variable
# plotting the points
plt.plot(x, y)
# naming the x axis
plt.xlabel('x - axis')
# naming the y axis
plt.ylabel('y - axis')
# giving a title to my graph
plt.title('My first graph!')
# function to show the plot
plt.show()
模型构建、预测和拟合
这是非常重要的阶段,现在您需要为您的问题创建模型,您可以使用这些算法Sklearn algo(您应该应用各种算法,如 Randomforest、lineardiscriminate、decisiontree、knn、svm 等,并且只选择给出好分数的算法)
这些示例代码是,
from sklearn.ensemble import RandomForestClassifier
#Building random forest classifier model
def random_forest_classifier(features, target):
"""
To train the random forest classifier with features and target data
:param features:
:param target:
:return: trained random forest classifier
"""
clf = RandomForestClassifier()
clf.fit(features, target)
return clf
做预测
现在您可以对您的测试数据进行预测,相同的示例代码是,
predictions = randomforestmodelis.predict(test_x)
for i in range(0, 5):
print("Actual outcome :: {} and Predicted outcome :: {}".format(list(test_y)[i], predictions[i]))
#print("Train Accuracy :: ", accuracy_score(train_y, randomforestmodelis.predict(train_x)))
print("Test Accuracy :: ", accuracy_score(test_y, predictions))
这应该可以解决您的问题。