Search code examples
pythonpandasdataframenumpydata-analysis

Python can't find analyze() script


In the book "Python Artificial Intelligence Projects for Beginners" by Joshua Eckroth, in the project about Youtube Spam, seems like it can't find the analyze() Does anyone know what has changed since the book was published in 2018?

>>>import pandas as pd
>>>d=pd.read_csv("Youtube01-Psy.csv")
>>>d
>>>d.tail()
>>>len(d.query("CLASS==1"))
>>>len(d.query("CLASS==0"))
>>>len(d)
>>>from sklearn.feature_extraction.text import CountVectorizer
>>>vectorizer = CountVectorizer()
>>>dvec = vectorizer.fit_transform(d["CONTENT"])
>>>dvec
>>>print(d["CONTENT"][349])
>>>analyze(d["CONTENT"][349])

Solution

  • If you want to use analyze() then first you have to

    • import this function from some module
    • or write this function in your code

    Using Google I searched Python Artificial Intelligence Projects for Beginners

    and on GitHub I found Python Artificial Intelligence Projects for Beginners
    and source code for Spam detector.py

    and there is line which you don't have

    analyze = vectorizer.build_analyzer()
    

    and this should resolve your problem.