SHARE
TWEET

Untitled

a guest May 23rd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def parse_data(filename):
  2.     """
  3.     This function parses the data for the decision tree algorithm
  4.     """    
  5.     header = filename.readline()
  6.     header = ([[str(y) for y in header.strip().split(" ")][1:]])
  7.     data = filename.readlines()
  8.     data = ([[int(y) for y in x.strip().split(" ")][1:] for x in data])
  9.     data = np.transpose(data)
  10.    
  11.     labels = np.transpose((data[-1,:]))
  12.     data = np.transpose((data[:-1,:]))
  13.     n = np.zeros(2)
  14.     total = 0
  15.     for x in labels:
  16.         if(x == 0):
  17.             n[0] = int(n[0]+1)
  18.             total = total+1
  19.         else:
  20.             n[1] = int(n[1]+1)
  21.             total = total+1
  22.  
  23.     return(data,header,labels,n,total)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top