Page MenuHomec4science

visu.py
No OneTemporary

File Metadata

Created
Sun, Jan 5, 07:29
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.inspection import permutation_importance
def plot_feature_importance(model, X_train, y_train, feature_names, output_path):
result = permutation_importance(model, X_train, y_train, n_repeats=10, random_state=42)
sorted_idx = result.importances_mean.argsort()
plt.figure(figsize=(12, 8))
plt.barh(range(len(sorted_idx)), result.importances_mean[sorted_idx], align='center')
plt.yticks(range(len(sorted_idx)), [feature_names[i] for i in sorted_idx])
plt.xlabel("Permutation Importance")
plt.title("Feature Importance")
plt.savefig(output_path)
plt.close()
def plot_feature_correlation(dataframe, output_path):
plt.figure(figsize=(12, 10))
corr_matrix = dataframe.corr()
sns.heatmap(corr_matrix, annot=True, fmt=".2f", cmap="coolwarm")
plt.title("Feature Correlation Matrix")
plt.savefig(output_path)
plt.close()
def plot_predicted_counts(predictions, df, output_path):
df['predictions'] = predictions
result = df.groupby('antibiotics_quantity')['predictions'].value_counts().unstack().fillna(0)
# Plotting side-by-side bars
result.plot(kind='bar', color=['orange', 'blue'], width=0.8)
plt.xlabel('Antibiotics Quantity')
plt.ylabel('Count')
plt.title('Predicted Dead/Alive Bacteria per Antibiotic Level')
plt.legend(title='Predictions', labels=['Dead', 'Alive'])
plt.savefig(output_path)
plt.close()

Event Timeline