不知道该叫什么——泰坦尼克号个人项目代码

写在前面

这一点点代码是分享会第一次留项目后我的作业代码,留此备记,也方便为其他同学的Adaboost提供弱分类器。

代码

# coding=utf-8
def predictions_qiu(data):
    """ Model with multiple features. Makes a prediction with an accuracy of at least 80%. """
    
    predictions = []
    for _, passenger in data.iterrows():
        if passenger[3] == 'female':
            if passenger[1] <= 2:  # female, Pclass 1、2. OVER
                predictions.append(1)
            else:  # female, Pclass 3
                if passenger[8] > 23.25:  # female, Pclass 3, Fare > 23.25
                    predictions.append(0)
                else:  # female, Pclass 3, Fare <= 23.25
                    if passenger[10] == 'Q':  # female, Pclass 3, Fare <= 23.25, Embarked =Q
                        if passenger[6] > 0:  # female, Pclass 3, Fare <= 23.25, Embarked =Q, Parch > 0
                            predictions.append(0)
                        else:  # female, Pclass 3, Fare <= 23.25, Embarked =C, Parch <= 0
                            if passenger[8] <= 7.65:
                                predictions.append(0)
                            else:
                                predictions.append(1)
                    elif passenger[10] == 'C':  # female, Pclass 3, Fare <= 23.25, Embarked=C
                        if passenger[8] > 15.246:
                            predictions.append(1)
                        else:
                            if passenger[8] > 13.863:
                                predictions.append(0)
                            else:
                                predictions.append(0)
                    else:  # female, Pclass 3, Fare <= 23.25, Embarked=S
                        if passenger[6] > 0:
                            predictions.append(1)
                        else:
                            predictions.append(0)
                
        else:  # male
            if passenger[4] > 10:  # # male, age > 10
                predictions.append(0)
            else:  # male, age < 10
                if passenger[5] > 2:  # male, age <= 10, SibSp > 2
                    predictions.append(0)
                else:  # male, age <= 10, SibSp <=2
                    if passenger[6] == 0:  # male, age <= 10, SibSp <=2, Parch == 0
                        predictions.append(0)
                    else:  # male, age <= 10, SibSp <=2, Parch > 0
                        predictions.append(1)
    return pd.Series(predictions)

我们的822,我们的青春
欢迎所有热爱知识热爱生活的朋友和822实验室一起成长,吃喝玩乐,享受知识。

你可能感兴趣的:(不知道该叫什么——泰坦尼克号个人项目代码)