0% found this document useful (0 votes)
2 views3 pages

Decision tree

The document describes the application of Decision Tree and Random Forest algorithms on a dataset related to kyphosis, a spinal condition, to predict whether patients have kyphosis after corrective surgery. It includes data preprocessing steps, model training, and evaluation metrics such as confusion matrices and classification reports. The results indicate varying levels of accuracy and performance between the two models.

Uploaded by

unknown2006103
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Decision tree

The document describes the application of Decision Tree and Random Forest algorithms on a dataset related to kyphosis, a spinal condition, to predict whether patients have kyphosis after corrective surgery. It includes data preprocessing steps, model training, and evaluation metrics such as confusion matrices and classification reports. The results indicate varying levels of accuracy and performance between the two models.

Uploaded by

unknown2006103
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Decision Tree algorthim used in the dataset of

Kyphosis which is spinal condition and the patient


had a operation operation has corrective final
surgery and the datasets shows either patients has
a kyphosis condition after surgery or not.
In [1]: import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline

In [2]: df=pd.read_csv('kyphosis.csv')

In [3]: df.head()

Out[3]: Kyphosis Age Number Start

0 absent 71 3 5

1 absent 158 3 14

2 present 128 4 5

3 absent 2 5 1

4 absent 1 4 15

In [4]: df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 81 entries, 0 to 80
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Kyphosis 81 non-null object
1 Age 81 non-null int64
2 Number 81 non-null int64
3 Start 81 non-null int64
dtypes: int64(3), object(1)
memory usage: 2.7+ KB

In [5]: sns.pairplot(df,hue='Kyphosis')
#in pairplot we find how the columns are related to each other and their distribution

<seaborn.axisgrid.PairGrid at 0x2d05afdef70>
Out[5]:
In [6]: from sklearn.model_selection import train_test_split

In [7]: X=df.drop('Kyphosis',axis=1)

In [8]: y=df['Kyphosis']

In [9]: X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)

In [10]: #to train single decision tree import


from sklearn.tree import DecisionTreeClassifier

In [11]: dtree=DecisionTreeClassifier()

In [12]: dtree.fit(X_train,y_train)

DecisionTreeClassifier()
Out[12]:

In [13]: prediction=dtree.predict(X_test)

In [14]: from sklearn.metrics import classification_report,confusion_matrix

In [15]: print(confusion_matrix(y_test,prediction))
print('\n')
print(classification_report(y_test,prediction))
[[22 0]
[ 3 2]]

precision recall f1-score support

absent 0.88 1.00 0.94 22


present 1.00 0.40 0.57 5

accuracy 0.89 27
macro avg 0.94 0.70 0.75 27
weighted avg 0.90 0.89 0.87 27

In [16]: from sklearn.ensemble import RandomForestClassifier

In [17]: rfc=RandomForestClassifier(n_estimators=200)

In [18]: rfc.fit(X_train,y_train)

RandomForestClassifier(n_estimators=200)
Out[18]:

In [19]: rfc_predict=rfc.predict(X_test)

In [20]: print(confusion_matrix(y_test,rfc_predict))
print('\n')
print(classification_report(y_test,rfc_predict))

[[22 0]
[ 4 1]]

precision recall f1-score support

absent 0.85 1.00 0.92 22


present 1.00 0.20 0.33 5

accuracy 0.85 27
macro avg 0.92 0.60 0.62 27
weighted avg 0.87 0.85 0.81 27

In [ ]:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy