<jupyter_start><jupyter_text><jupyter_code>from google.colab import files
uploaded = files.upload()<jupyter_output><empty_output><jupyter_text><jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv('HD_Cleveland_Data_Clean.csv')
df
df.info()
#How to get statistical informatipn about dataset
df.describe()
#Let's try EDA
df['target'].value_counts()
sns.countplot(x='target',data=df, hue='sex',palette='coolwarm') #male = 1 female = 0
sns.countplot(x='thal',data=df,palette='coolwarm', hue='sex')
sns.jointplot(x='age',y='chol',data=df)
#Machine Learning section 1, You have to divide the dataset into train and test
from sklearn.model_selection import train_test_split
X=df.drop('target',axis=1)
y=df['target'] #key factor should be taken in y
#now divide into test and train
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.33, random_state=101)
X_test
X_train
#Decision trees - We will start with training a single decision tree
#importing decision tree classifier

from sklearn.tree import DecisionTreeClassifier
#creating instance "dtree" of the classifier

dtree = DecisionTreeClassifier()
#fitting to the training data the default parameters are fine at section
dtree.fit(X_train, y_train)
#predictions and evolutions
#how to do predictions with tree

predictions = dtree.predict(X_test)
#How to develop classification report and confusion matrix
from sklearn.metrics import classification_report,confusion_matrix
print(classification_report(y_test,predictions))
print(confusion_matrix(y_test,predictions))
#Random Forest
from sklearn.ensemble import RandomForestClassifier
df
#We need to pass the number of trees in the forest which is n_estimators. Normally we take default value 8-10
#creating instance and fitting the model

rfc = RandomForestClassifier(n_estimators=100)
rfc.fit(X_train,y_train)
#let's do the predictions with forest
rfc_pred=rfc.predict(X_test)
#Evaluation Matrix
print(classification_report(y_test,rfc_pred))
print(confusion_matrix(y_test,rfc_pred))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09012875536480687, 'fraction_numerical': 0.007629947544110634, 'mean_word_length': 7.852320675105485, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '15647', 'license': 'Apache-2.0', 'n_tokens_mistral': 706, 'n_tokens_neox': 675, 'n_words': 200, 'path': 'heartdisease.ipynb', 'repo_name': 'missjaanii/heartdiseaseprediction', 'size': '2097'}