NF Assighment4
NF Assighment4
NF Assighment4
import pandas as pd
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, f1_score, classification_report
from sklearn.ensemble import RandomForestClassifier
1 of 5 4/30/2024, 12:05 PM
Welcome To Colab - Colab https://colab.research.google.com/#scrollTo=7-debQKryIG3&printMod...
data = pd.read_csv('annthyroid_21feat_normalised.csv')
# Optionally, you can include other metrics such as precision, recall, confusion matrix, etc.
Accuracy: 0.9993055555555556
F1 Score: 0.9993036997916849
Classification Report:
precision recall f1-score support
2 of 5 4/30/2024, 12:05 PM
Welcome To Colab - Colab https://colab.research.google.com/#scrollTo=7-debQKryIG3&printMod...
plt.figure(figsize=(8, 6))
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues', xticklabels=['Normal', 'Anomaly'], yticklabels
plt.xlabel('Predicted Label')
plt.ylabel('True Label')
plt.title('Confusion Matrix')
plt.show()
plt.figure(figsize=(10, 8))
plt.barh(range(len(sorted_idx)), feature_importances[sorted_idx], align='center')
plt.yticks(range(len(sorted_idx)), [feature_names[i] for i in sorted_idx])
plt.xlabel('Feature Importance')
plt.ylabel('Feature')
plt.title('Feature Importances')
plt.show()
3 of 5 4/30/2024, 12:05 PM
Welcome To Colab - Colab https://colab.research.google.com/#scrollTo=7-debQKryIG3&printMod...
4 of 5 4/30/2024, 12:05 PM
Welcome To Colab - Colab https://colab.research.google.com/#scrollTo=7-debQKryIG3&printMod...
5 of 5 4/30/2024, 12:05 PM