Random forest classification
A tutorial On how to use Random forest classification.
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
dataset = pd.read_csv("heart-disease.csv")
dataset
dataset.isna().sum()
dataset.info()
X = dataset.drop("target", axis=1)
X.head()
y = dataset["target"]
y.head()
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 2509)
from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(random_state=2509)
classifier.fit(X_train, y_train)
classifier.score(X_test,y_test)
y_pred = classifier.predict(X_test)
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
print(cm)
from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred))