Advertisement
2n2u

Untitled

Mar 31st, 2016
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. from numpy import genfromtxt
  4. from copy import copy
  5.  
  6. X = genfromtxt('data1', delimiter=',')
  7. Y = genfromtxt('Y', delimiter=',')
  8. Y = np.float32(Y)
  9.  
  10.  
  11. print X[0, :]
  12.  
  13. sample_n, var_n = X.shape
  14. var_types = np.array([cv2.CV_VAR_NUMERICAL] * var_n + [cv2.CV_VAR_ORDERED], np.float32)
  15.  
  16. model = cv2.RTrees()
  17.  
  18. params = dict(max_depth=10, max_num_of_trees_in_the_forest=10, cv_folds=5, regression_accuracy=0.0001)
  19.  
  20. features = ['PEF', 'FEV1', 'FVC', 'TIFF']
  21.  
  22. a = model
  23.  
  24. save_f = np.zeros((np.shape(X)[0], np.shape(X)[1]/len(features)))
  25. save_all = {}
  26.  
  27. for r in xrange(0, len(features)):
  28.     for j in xrange(0, np.shape(X)[0]):
  29.         u = 0
  30.         for i in range(r, np.shape(X)[1], len(features)):
  31.             save_f[j, u] = X[j, i]
  32.             u += 1
  33.     save_all[features[r]] = copy(np.float32(save_f))
  34.  
  35. print 'save_all'
  36. for r in xrange(0, len(features)):
  37.     print save_all[features[r]][0, :]
  38.  
  39. print X.dtype
  40. print Y.dtype
  41.  
  42. #print Y
  43.  
  44.  
  45. print save_all['PEF'].dtype
  46.  
  47. for i in range(0, len(features)):
  48.     print 'Starting: ' + features[i]
  49.  
  50.     #print (X[train,:][:, [0,4,8,12,16,20]])
  51.     print 'one cycle'
  52.     print save_all[features[i]]
  53.     print (Y[:][:, 0])
  54.     print save_all[features[i]].shape
  55.     print (Y[:][:, 0]).shape
  56.     a.train(save_all[features[i]], cv2.CV_ROW_SAMPLE, Y[:][:, i], params=params, varType=var_types)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement