0

I'm a beginner in Machine Learning and I'm learning through the Kaggle competitions. I've started off with the Titanic competition and now I'm trying to measure the accuracy of my prediction with the scikit-learn accuracy_score function but the output does not really make sense. Here is the output I am getting:

[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>

And here is my code:

*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)
Onur-Andros Ozbek
  • 2,998
  • 2
  • 29
  • 78
  • 1
    You are printing the function `accuracy_score` and not what the function returns, thats why you see ``. Save the value of `accuracy_score(val_y, val_predictions)` into a variable and print that variable. – danielfrg Jul 20 '18 at 05:58
  • "I'm a beginner in Machine Learning" ... This question seems to demonstrate that you are a beginner at programming in general. Perhaps a short python course would help? I learned with [Google's python course](https://developers.google.com/edu/python/) years ago. It's a bit fast paced and terse, however, but there are a [huge number of others out there](https://wiki.python.org/moin/BeginnersGuide/NonProgrammers) – Him Jul 20 '18 at 14:09
  • @Scott if a simple mistake made someone a beginner, then there are no senior developers. I'm an Android developer, mate. Settle down. – Onur-Andros Ozbek Jul 21 '18 at 01:03
  • @OnurOzbek, not trying to have a measuring contest, just noting that you're jumping into the deep end of the python pool. [Google's python course](https://developers.google.com/edu/python/) is right up your alley then, since it is geared toward those who already have some knowledge of programming. – Him Jul 21 '18 at 03:17

2 Answers2

3

You need to print the results of the accuracy_score(val_y, val_predictions) line.

e.g. print(accuracy_score(val_y, val_predictions))

Him
  • 5,257
  • 3
  • 26
  • 83
1

Either annotate accuracy_score in a variable acc= accuracy_score(predictions,val_y) print (acc) Or print the accuracy_score print accuracy_score(predictions,val_y)