Python Forum

Full Version: Adding a subroutine to a larger program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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
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?