[Need Help] Fake news detector application using python

Hi,
I’m new to this domain, so I need someone to explain me this code, because I dont understand very well the part with “0” and “1” from prediction[0] and prob[0][1].

import pickle
var = input("Please enter the news that you want to verify: ")
#print(“You entered:” + str(var))

def fakenews(var):
load_model = pickle.load(open(‘model.sav’, “rb”))
prediction = load_model.predict([var])
prob = load_model.predict_proba([var])

return (print("The given statement is: ", prediction[0]),
       print("The truth probability score is: ", prob[0][1]))

if name == ‘main’:
fakenews(var)

Thank you!

@p.a.t.r.i.c.i.a , here, prediction and prob are lists or arrays.

A list has more than one element.
x = [1,200,3,4,5]
x[0] refers to the first element (1)
x[1] referees to the second element (200)… and so on.
Notice the 0-based indexing.

So prediction is a list having the list of predictions the model believes the text belongs to.
prediction[0] refers to the first prediction.

prob is a 2-dimensional list.
lists can be multi-dimensional.

say

z = [[1,10],
[2,20],
[3,30]]

then z[0][0] refers to 1, z[0][1] refers to 10, z[2][1] refers to 30 and so on.

1 Like
© Copyright 2013-2019 Analytics Vidhya