数据分析方法

时间:2017-12-08 07:26:51

标签: python machine-learning data-analysis data-science

我有一份新毕业生员工的数据集,他们的GPA分数以及他们是否在试用期后被雇用或解雇。老板要求我分析大学GPA是否对雇用或解雇有重大影响。有时还可以包括其他功能,如大学排名等。老板现在对数据科学和机器学习感兴趣。但我还没有任何数据分析方面的经验所以请告诉我如何处理这个问题以及我应该学会做什么?我有编程背景(知道python),所以欢迎技术术语。

2 个答案:

答案 0 :(得分:1)

考虑到他们的GPA,大学排名等特征,你试图预测应届毕业生的就业状况。

您的问题可被视为"二进制分类问题"因为您的输出应该被解雇/雇用为(0或1)

Training_set :首先,您需要创建一个包含功能及其实际输出的训练集。

功能分析:尝试使用以下内容分析数据如何影响输出:

train = pd.read_csv('../input/train.csv')
print (train[["GPA", "Employment_status"]].groupby(['GPA'], as_index=False).mean())

训练算法:有许多机器学习算法可用于解决SVM,决策树,KNN等二进制分类问题。 您还可以进行异常检测,您可以使用其中一个输出拟合分布。 使用sklearn库,因为它们易于使用,并且还提供各种算法。

检查this以了解有关sklearn的更多信息。

测试:最后使用测试集测试您的模型并计算精度,以了解模型如何适合数据。

通过andrew ng查看讲座,因为对于正在开始机器学习的人来说,它们很容易理解。找到它here

数据可视化:

Kaggle是学习新方法和算法的最佳平台之一检查this链接,因为它提供了有关如何在Iris数据集上使用不同数据可视化工具的信息。

检查this MOOC以了解有关数据可视化的更多信息。

数据可视化将帮助您了解功能的相关性。

答案 1 :(得分:1)

在这些中,您基本上是在预测大学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和大学排名是特征变量。并且你的目标变量被雇佣/解雇(1或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))

这应该可以解决你的问题。