0

I am trying to get relative importance of each feature on individual rock type along with the it's feature name. I did the following:

for y_train_all, y_strings_all in zip(y_trains_classes, 
                                      y_classes_names):
    grid_for.fit(X_train, y_train_all)
    feature_importances = grid_for.best_estimator_.feature_importances_
    attributes_all = ["Depth" ,"Neutron Porosity","Caliper ", "Density Porosity","Gamma Ray",
                      "Photoelectric", "Bulk Density", "Density Correction", "Resistivity (Deep)", 
                       "Resistivity (Medium)", "Resistivity (Shallow)","Ratio(Shallow/Deep resistivity)",
                      "SP",  "Micro-inverse (resistivity) micro-log", "Micro-normal (resistivity) micro-log", 
                    "Delta-t (transit time)", "Sonic Porosity"]
    print("\n", "Features importance of", y_strings_all, "= \n", sorted(zip(feature_importances*100, attributes_all), 
                                                                  reverse=True))

I get this for one of the rock type:

Features importance of shaly limestone = 
 [(32.698676805752939, 'Depth'), (11.437112671467331, 'Gamma Ray'), (7.0256677233376346, 'SP'), (5.2919610063076963, 'Density Correction'), (4.69972333501756, 'Resistivity (Deep)'), (4.3250282898616081, 'Caliper '), (3.876972448849632, 'Micro-normal (resistivity) micro-log'), (3.8373287915693957, 'Resistivity (Medium)'), (3.6854852718774076, 'Photoelectric'), (3.6552972972995796, 'Sonic Porosity'), (3.5872666770164936, 'Micro-inverse (resistivity) micro-log'), (3.5667515140079744, 'Delta-t (transit time)'), (2.7913023534006003, 'Resistivity (Shallow)'), (2.714697087901786, 'Neutron Porosity'), (2.4667204236786993, 'Ratio(Shallow/Deep resistivity)'), (2.1928475922610642, 'Density Porosity'), (2.1471607103925967, 'Bulk Density')]

When I did it for just one type of rock I got the printed results this smooth:

[(32.698676805752939, 'Depth'),
 (11.437112671467331, 'Gamma Ray'),
 (7.0256677233376346, 'SP'),
 (5.2919610063076963, 'Density Correction'),
 (4.69972333501756, 'Resistivity (Deep)'),
 (4.3250282898616081, 'Caliper'),
 (3.876972448849632, 'Micro-normal (resistivity) micro-log'),
 (3.8373287915693957, 'Resistivity (Medium)'),
 (3.6854852718774076, 'Photoelctric'),
 (3.6552972972995796, 'Sonic Porosity'),
 (3.5872666770164936, 'Micro-inverse (resistivity) micro-log'),
 (3.5667515140079744, 'Delta-t (transit time)'),
 (2.7913023534006003, 'Resistivity (Shallow)'),
 (2.714697087901786, 'Neutron Porosity'),
 (2.4667204236786993, 'Ratio(Shallow/Deep resistivity)'),
 (2.1928475922610642, 'Density Porosity'),
 (2.1471607103925967, 'Bulk Density')]

How can I make the printed solution look as smooth (one feature_importance in one line) as when I got the answer for only one rock type?

SMAmir
  • 75
  • 1
  • 12
  • Does this help?: https://stackoverflow.com/questions/493386/how-to-print-without-newline-or-space – ZaxR Apr 07 '18 at 23:28
  • No it's still behaving the same way after I added a `end = ' '` statement at the at end of the print statement. I tried to get the print command to print in the for loop like mentioned in the question as well but it didn't do anything – SMAmir Apr 07 '18 at 23:56
  • I'm having trouble recreating the problem. What interpreter/environment are you using? What generates results the first way vs the second way..? What is each input variable equal to? – ZaxR Apr 08 '18 at 01:33
  • In the first way I just get the results by `sorted(zip(...))` statement as you can see in the first part of the code under the for loop. When I put each type of rock in the `for` loop as you can see I get the results in the same line one after the other and looks messy. In the second way I just get the results for one type of rock without using the print statement. Seems like if I put the statement under the `for` loop, I need to use the print statement to get the answers and in the other way I don't and it prints neatly one `feature_importance` in one line. – SMAmir Apr 08 '18 at 20:14

0 Answers0