python - "Got 1 columns instead of ..." error in numpy -


I am working on the following code for random forest classification on train and test sets;

 Scheln. Import from RandomForestClassifier numpy import from genfromtxt, savetxt def main (): dataset = genepromast (open ('file path', 'r'), delimiter = '', dtype = 'f8') target = [x for x in dataset [0] Train = [X [1:] for X in the dataset) test = genfromtxt (open ('file path', 'r'), delimiter = '', dtype = 'f8') rf = RandomForestClassifier (N_estimators = 100 ) Rf.fit (train, target) predicted_probs = [[index + 1, x [1]] for index, enumerate in x (rf.predict_proba (test)] savetxt ('filepath', predicted_probs, delimiter = ', ', Fmt ='% d,% f ', header =' id, estimation 'Qualification', comments = '') if __ name __ == "__ Muky__": main ()  

However, I get the following error on execution;

  ----> Dataset = GenePromatex ('C: /Users / Saurabh / Desktop / pgm / Kora / A_Train CCV', 'R'), Delimiter = '', DTP = 'F8') Value Error: Some Errors Found! Line # 88 (1435 columns instead of 1434) Line # 164 (1435 columns instead of 1434) Line # 169 (1435 columns instead of 1434 get) Line # 524 (1435) Line # 93 (1435 columns instead of 1434) Found) column instead of 1434) ... ... ...  

How to avoid any suggestions ?? Thank you.

genfromtxt will give this error if the number of columns is uneven.

I can think of three ways around it:

1 parameter

  np.genfromtxt (' Use yourfile.txt ', Delimiter =', ', usecols = np.arange (0,1434))  

However - this may mean that you lose some data (Where rows have more than 1434 columns) - regardless of the case.

2. Adjust your input data file so that it has an equal number column

3 genfromtxt:

.............


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -