“Got 1 columns instead of …” error in numpy

后端 未结 8 702
傲寒
傲寒 2021-01-17 13:00

I\'m working on the following code for performing Random Forest Classification on train and test sets;

from sklearn.ensemble import RandomForestClassifier
fr         


        
8条回答
  •  一向
    一向 (楼主)
    2021-01-17 13:32

    An exception is raised if an inconsistency is detected in the number of columns.A number of reasons and solutions are possible.

    1. Add invalid_raise = False to skip the offending lines.

      dataset = genfromtxt(open('data.csv','r'), delimiter='', invalid_raise = False)

    2. If your data contains Names, make sure that the field name doesn’t contain any space or invalid character, or that it does not correspond to the name of a standard attribute (like size or shape), which would confuse the interpreter.

    1. deletechars

      Gives a string combining all the characters that must be deleted from the name. By default, invalid characters are ~!@#$%^&*()-=+~\|]}[{';: /?.>,<.

    2. excludelist

      Gives a list of the names to exclude, such as return, file, print… If one of the input name is part of this list, an underscore character ('_') will be appended to it.

    3. case_sensitive

      Whether the names should be case-sensitive (case_sensitive=True), converted to upper case (case_sensitive=False or case_sensitive='upper') or to lower case (case_sensitive='lower').

    data = np.genfromtxt("data.txt", dtype=None, names=True,\
           deletechars="~!@#$%^&*()-=+~\|]}[{';: /?.>,<.", case_sensitive=True)
    

    Reference: numpy.genfromtxt

提交回复
热议问题