Professional Documents
Culture Documents
ML Lab 5
ML Lab 5
ipynb - Colab
breast = load_breast_cancer()
X = breast.data
y = breast.target
rf = RandomForestClassifier(n_estimators=100, random_state=42)
rf.fit(X_train, y_train)
▾ RandomForestClassifier
RandomForestClassifier(random_state=42)
y_pred = rf.predict(X_test)
print(classification_report(y_test, y_pred))
print(accuracy_score(y_test, y_pred))
0.9649122807017544
print(classification_report(y, y_pred_c))
print(accuracy_score(y, y_pred_c))
0.9560632688927944
plt.figure(figsize=(50,50))
for i in range(3):
plt.subplot(3, 1, i+1)
plot_tree(rf.estimators_[i], filled=True, feature_names=breast.feature_names, class_names=['Disease', "No Disease"])
plt.show()
https://colab.research.google.com/drive/1vPVh3WYBZOIvQJrxmedAf1cnVcxXl8Jh#scrollTo=sKVVlZ5JjRnn&printMode=true 1/2
4/16/24, 10:48 PM ML Lab5.ipynb - Colab
https://colab.research.google.com/drive/1vPVh3WYBZOIvQJrxmedAf1cnVcxXl8Jh#scrollTo=sKVVlZ5JjRnn&printMode=true 2/2