Python Forum
Adding a subroutine to a larger program - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Adding a subroutine to a larger program (/thread-39233.html)



Adding a subroutine to a larger program - Led_Zeppelin - Jan-18-2023

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


RE: Adding a subroutine to a larger program - Led_Zeppelin - Jan-18-2023

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


RE: Adding a subroutine to a larger program - deanhystad - Jan-18-2023

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?