Python Forum
Adding a subroutine to a larger program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding a subroutine to a larger program
#1
The following program was written by me. I wanted to plot feature importance against sensor number on a two-dimensional plot. The X axis has the sensor number, and the Y axis has feature importances.

import pandas as pd
import matplotlib.pyplot as plt

# Load the data 
data = pd.read_csv("sensor_data.csv", header=None)

# Extract the feature names and importance values
feature_names = range(0,51)
importances = data[0]

# Plot the data
plt.figure(figsize=(10, 5))
plt.title("Feature Importance")
plt.bar(feature_names, importances)
plt.xlabel("Sensor Index")
plt.ylabel("Importance Value")
plt.show()
Now I want to add this python code to the python program in the attachment, so I have a plot of the data instead of just a vector.

I am not sure how.

Any help appreciated.

R,

Led Zeppelin

Attached Files

Thumbnail(s)
   
Reply
#2
I thought of modifying the code that I posted. to something like this:

import pandas as pd
import matplotlib.pyplot as plt

# Load the data 
data = ext.sort.values(['extratrees'], ascending=True)

# Extract the feature names and importance values
feature_names = range(0,51)
importances = data[0]

# Plot the data
plt.figure(figsize=(10, 5))
plt.title("Feature Importance")
plt.bar(feature_names, importances)
plt.xlabel("Sensor Index")
plt.ylabel("Importance Value")
plt.show()
But that seems very awkward. So, I hope there is an easier way.

Any help appreciated.

Respectfully,

Led_Zeppilin
Reply
#3
What do you find awkward about it? Is it that you are including the values instead of reading a file? Where do the values from the CSV file come from? Are they produced by your notebook?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  An unexplainable error in .format statement - but only in a larger piece of code? ToniE 4 728 Sep-05-2023, 12:50 PM
Last Post: ToniE
  Adding markers to Folium map only adding last element. tantony 0 2,136 Oct-16-2019, 03:28 PM
Last Post: tantony
  keypad loops/subroutine help arbrunso 1 3,034 Jul-18-2018, 09:39 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020