numpyscikit-learnspydernp

Binarization in Spyder(Python 3.9) code using sk-learn(preprocessing) and NumPy


I attach a screenshot of the code I am new to Python and am currently studying artificial intelligence, working in Spyder(python 3.9)

After executing the code, I expected this output

Binarized data:
    [[1.о.1.]
    [о.1.о.]
    [1.о.о.]
    [1.о.о.]]

Solution

  • In Python it is important to write one command in one line:

    data_binarized = preprocessing.Binarizer(your_code)
    

    If you want to write it in two lines, you can use implicit line continuation (Possible only inside parentheses, brackets and braces):

    data_binarized = preprocessing.Binarizer(
                     your_code)
    

    As an second possible option you can use the backslash (explicit line continuation):

    data_binarized =\
    preprocessing.Binarizer(your_code)
    

    For more information about this look at this answer:

    https://stackoverflow.com/a/4172465/21187993