Scikit-Learn准确性分数未显示准确性

时间:2018-07-20 05:46:25

标签: python machine-learning scikit-learn anaconda kaggle

我是机器学习的初学者,并且正在通过Kaggle比赛学习。我从泰坦尼克号竞赛开始,现在我正尝试使用scikit-learn accuracy_score函数来衡量我的预测的准确性,但是输出实际上没有任何意义。这是我得到的输出:

[1. 0. 1. 0. 1. 0. 0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
 1. 0. 1. 1. 0. 0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0. 1. 0. 1.]

<function accuracy_score at 0x000001AA46EFBD90>

这是我的代码:

*imports have been omitted to avoid crowding

    train_path = "C:\\Users\\Omar\\Downloads\\Titanic Data\\train.csv"
    train_data = pd.read_csv(train_path)

    train_data['Sex'] = pd.factorize(train_data.Sex)[0]

    columns_of_interest = ['Survived','Pclass', 'Sex', 'Age']
    filtered_titanic_data = train_data.dropna(axis=0)

    x = filtered_titanic_data[columns_of_interest]
    y = filtered_titanic_data.Survived

    train_x, val_x, train_y, val_y = train_test_split(x, y, random_state=0)

    titanic_model = DecisionTreeRegressor()
    titanic_model.fit(train_x, train_y)

    val_predictions = titanic_model.predict(val_x)
    accuracy_score(val_y, val_predictions)

    print(val_predictions)
    print(accuracy_score)

2 个答案:

答案 0 :(得分:3)

您需要打印accuracy_score(val_y, val_predictions)行的结果。

例如print(accuracy_score(val_y, val_predictions))

答案 1 :(得分:1)

在变量中注释precision_score acc = precision_score(predictions,val_y) 列印(acc) 或打印precision_score 打印precision_score(predictions,val_y)