Friday, 15 January 2010

numpy - create a feature vector using pandas or python -


I have a binary classifier that takes 200 element input feature vectors as shown below

  [id, v1, v2, ..., v190, v200, square] [7, 0, 0, ..., 0, 0, 0], [8, 0, 1, ..., 0, 0, 1], [9, 0, 0, ..., 0, 0, 1],  

For each element, X can have any set of attributes Is v1-v200

  sql = 'SELECT x_id, x_attr elements by WHERE x_hash =% s' cur.execute (sql, (x_hash,)) x1 = cur.fetchone () x1 # x1 ID and a list gives properties (123, [v2, v56, v200]) that the output is one i If you want to create one above the feature vector, if any attribute in the list matches any attribute, in v1-v200 it will be set as 1.  
  [id, v1, v2, ..., v56, ..., v190, v200, square], [123], 0, 1, ..., 1, .. ., 0, 1,? ],  

How can I do panda or python?

First initialize a panda dataframe and then create it on your example:

  Df = pd.DataFrame (none, column = ['v' + str (i) in category (1,201)] sql = 'SELECT x_id, x_attr from elements x_hash =% s' cur.execute (Sql, (x_hash,)) x1_id, features = cur.fetchone () df.loc [x1_id] = 0 # All values ​​of id for zero initiates Df.loc [x1_id, FEATURES] = 1 # Price of a Sets related attributes for  

because I have not included the class, because I was not sure how you were using it.


No comments:

Post a Comment