lolamontes69

Ch8 Ex3-Programming Collective Intelligence

Aug 12th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. """ Chapter 8 Exercise 3: Eliminating variables.
  2.  
  3.    Rather than trying to optimize variable scales for a large set of variables that are probably useless, you could try to eliminate variables that make the prediction worse before doing anything else.
  4.    Can you think of a way to do this?
  5.  
  6.    This creates a deepcopy of 'data', so the original remains unchanged, then removes the specified indices from the 'input' sections in the dictionaries,(So you can try removing variables without losing the original loaded dataset.)
  7.    The second obvious approach is not to import the variables into the dataset in the first place :)
  8.    See end for usage.
  9. """
  10.  
  11. def elim_variables(data,remove_list):
  12.     from copy import deepcopy
  13.     data1 = deepcopy(data)
  14.     for row in range(len(data1)):
  15.         list1=[]
  16.         for a in range(len(data1[row]['input'])):    
  17.             if a in remove_list: pass
  18.             else: list1.append(data1[row]['input'][a])
  19.         data1[row]['input']=list1
  20.     return data1
  21.  
  22. """
  23.   usage
  24.   *****
  25. import numpredict as numpredict
  26.  
  27. data = numpredict.wineset1()
  28. data1 = elim_variables(data,[0,3])     # Indices of data['input']
  29. """
Advertisement
Add Comment
Please, Sign In to add comment