Rough set: Quick reduct/ feature selection in Python





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I need to implement quick reduct algorithm for feature selection based on the rough sets, for that, I used cancer breast dataset, I get some errors and even if the code run the result is false ( comparing to R).



Original data set



Discretized data set



import numpy as np
import pandas as pd
#_______________________ File selection box
filename = 'breast10D.csv' # show an "Open" dialog box and return the path to the selected file
#Cfilename ='breast10.csv'
#_______________________ Converting csv file to list
df = pd.read_csv(filename)#,index_col=True)
U = df.values.tolist()
U = [[index] + value for index , value in enumerate(U) ]
#________________________ Equivalence partition function
def equivalence_partition( iterable , index ):
classes =
dclasses = {}
for o in iterable: # for each object
# find the class it is in
found = False
for c in classes:
indice_ele = next(iter(c))
element = [iterable[indice_ele][ind] == o[ind] for ind in index]
if all(element): # is it equivalent to this class?
c.add( o[0])
dclasses[o[0]] = c
found = True
break
if not found: # it is in a new class
classes.append( set([o[0]]))
dclasses[o[0]] = classes[-1]
return classes,dclasses
#_________________________ Finding lower approximation and positif region
def lower_appr(B):
ind_B = equivalence_partition( U , B )[1]
ind_d = equivalence_partition( U , D )[1]
lower_appr_set = set()
for x,ele in enumerate(U):
if ind_B[x].issubset(ind_d[x]):
lower_appr_set.add(x)
return lower_appr_set
#________________________ Finding dependencey of features
def gamma(B):
return float(len(lower_appr(B)))/float(len(U))
#_________________________ Rough set feature selection quickreduct algorithm
def qreduct(C):
R = set()
while True:
T = R
for x in C-R:
if gamma(R.union(set([x]))) > gamma(T):
T = R.union(set([x]))

R = T
if gamma(R) == gamma(C):
break
return R
#_________________________ Main fuction
decision=len(df.columns)#_________ defining le decision index
D = [decision]
B = set([ i for i in range(1,decision)]) #__________ defining condition index
Features= qreduct(B)


Does anyone have a suggestion?










share|improve this question































    1















    I need to implement quick reduct algorithm for feature selection based on the rough sets, for that, I used cancer breast dataset, I get some errors and even if the code run the result is false ( comparing to R).



    Original data set



    Discretized data set



    import numpy as np
    import pandas as pd
    #_______________________ File selection box
    filename = 'breast10D.csv' # show an "Open" dialog box and return the path to the selected file
    #Cfilename ='breast10.csv'
    #_______________________ Converting csv file to list
    df = pd.read_csv(filename)#,index_col=True)
    U = df.values.tolist()
    U = [[index] + value for index , value in enumerate(U) ]
    #________________________ Equivalence partition function
    def equivalence_partition( iterable , index ):
    classes =
    dclasses = {}
    for o in iterable: # for each object
    # find the class it is in
    found = False
    for c in classes:
    indice_ele = next(iter(c))
    element = [iterable[indice_ele][ind] == o[ind] for ind in index]
    if all(element): # is it equivalent to this class?
    c.add( o[0])
    dclasses[o[0]] = c
    found = True
    break
    if not found: # it is in a new class
    classes.append( set([o[0]]))
    dclasses[o[0]] = classes[-1]
    return classes,dclasses
    #_________________________ Finding lower approximation and positif region
    def lower_appr(B):
    ind_B = equivalence_partition( U , B )[1]
    ind_d = equivalence_partition( U , D )[1]
    lower_appr_set = set()
    for x,ele in enumerate(U):
    if ind_B[x].issubset(ind_d[x]):
    lower_appr_set.add(x)
    return lower_appr_set
    #________________________ Finding dependencey of features
    def gamma(B):
    return float(len(lower_appr(B)))/float(len(U))
    #_________________________ Rough set feature selection quickreduct algorithm
    def qreduct(C):
    R = set()
    while True:
    T = R
    for x in C-R:
    if gamma(R.union(set([x]))) > gamma(T):
    T = R.union(set([x]))

    R = T
    if gamma(R) == gamma(C):
    break
    return R
    #_________________________ Main fuction
    decision=len(df.columns)#_________ defining le decision index
    D = [decision]
    B = set([ i for i in range(1,decision)]) #__________ defining condition index
    Features= qreduct(B)


    Does anyone have a suggestion?










    share|improve this question



























      1












      1








      1


      3






      I need to implement quick reduct algorithm for feature selection based on the rough sets, for that, I used cancer breast dataset, I get some errors and even if the code run the result is false ( comparing to R).



      Original data set



      Discretized data set



      import numpy as np
      import pandas as pd
      #_______________________ File selection box
      filename = 'breast10D.csv' # show an "Open" dialog box and return the path to the selected file
      #Cfilename ='breast10.csv'
      #_______________________ Converting csv file to list
      df = pd.read_csv(filename)#,index_col=True)
      U = df.values.tolist()
      U = [[index] + value for index , value in enumerate(U) ]
      #________________________ Equivalence partition function
      def equivalence_partition( iterable , index ):
      classes =
      dclasses = {}
      for o in iterable: # for each object
      # find the class it is in
      found = False
      for c in classes:
      indice_ele = next(iter(c))
      element = [iterable[indice_ele][ind] == o[ind] for ind in index]
      if all(element): # is it equivalent to this class?
      c.add( o[0])
      dclasses[o[0]] = c
      found = True
      break
      if not found: # it is in a new class
      classes.append( set([o[0]]))
      dclasses[o[0]] = classes[-1]
      return classes,dclasses
      #_________________________ Finding lower approximation and positif region
      def lower_appr(B):
      ind_B = equivalence_partition( U , B )[1]
      ind_d = equivalence_partition( U , D )[1]
      lower_appr_set = set()
      for x,ele in enumerate(U):
      if ind_B[x].issubset(ind_d[x]):
      lower_appr_set.add(x)
      return lower_appr_set
      #________________________ Finding dependencey of features
      def gamma(B):
      return float(len(lower_appr(B)))/float(len(U))
      #_________________________ Rough set feature selection quickreduct algorithm
      def qreduct(C):
      R = set()
      while True:
      T = R
      for x in C-R:
      if gamma(R.union(set([x]))) > gamma(T):
      T = R.union(set([x]))

      R = T
      if gamma(R) == gamma(C):
      break
      return R
      #_________________________ Main fuction
      decision=len(df.columns)#_________ defining le decision index
      D = [decision]
      B = set([ i for i in range(1,decision)]) #__________ defining condition index
      Features= qreduct(B)


      Does anyone have a suggestion?










      share|improve this question
















      I need to implement quick reduct algorithm for feature selection based on the rough sets, for that, I used cancer breast dataset, I get some errors and even if the code run the result is false ( comparing to R).



      Original data set



      Discretized data set



      import numpy as np
      import pandas as pd
      #_______________________ File selection box
      filename = 'breast10D.csv' # show an "Open" dialog box and return the path to the selected file
      #Cfilename ='breast10.csv'
      #_______________________ Converting csv file to list
      df = pd.read_csv(filename)#,index_col=True)
      U = df.values.tolist()
      U = [[index] + value for index , value in enumerate(U) ]
      #________________________ Equivalence partition function
      def equivalence_partition( iterable , index ):
      classes =
      dclasses = {}
      for o in iterable: # for each object
      # find the class it is in
      found = False
      for c in classes:
      indice_ele = next(iter(c))
      element = [iterable[indice_ele][ind] == o[ind] for ind in index]
      if all(element): # is it equivalent to this class?
      c.add( o[0])
      dclasses[o[0]] = c
      found = True
      break
      if not found: # it is in a new class
      classes.append( set([o[0]]))
      dclasses[o[0]] = classes[-1]
      return classes,dclasses
      #_________________________ Finding lower approximation and positif region
      def lower_appr(B):
      ind_B = equivalence_partition( U , B )[1]
      ind_d = equivalence_partition( U , D )[1]
      lower_appr_set = set()
      for x,ele in enumerate(U):
      if ind_B[x].issubset(ind_d[x]):
      lower_appr_set.add(x)
      return lower_appr_set
      #________________________ Finding dependencey of features
      def gamma(B):
      return float(len(lower_appr(B)))/float(len(U))
      #_________________________ Rough set feature selection quickreduct algorithm
      def qreduct(C):
      R = set()
      while True:
      T = R
      for x in C-R:
      if gamma(R.union(set([x]))) > gamma(T):
      T = R.union(set([x]))

      R = T
      if gamma(R) == gamma(C):
      break
      return R
      #_________________________ Main fuction
      decision=len(df.columns)#_________ defining le decision index
      D = [decision]
      B = set([ i for i in range(1,decision)]) #__________ defining condition index
      Features= qreduct(B)


      Does anyone have a suggestion?







      python python-3.x machine-learning feature-selection fuzzy






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 27 '18 at 14:19







      mourad

















      asked Jun 26 '18 at 10:50









      mouradmourad

      175




      175
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51041066%2frough-set-quick-reduct-feature-selection-in-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51041066%2frough-set-quick-reduct-feature-selection-in-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine