Classification_With_Decision_Tree_MarketingData - Jupyter Notebook
Classification_With_Decision_Tree_MarketingData - Jupyter Notebook
In [1]: #Building Decision Tree classification model with Python Step by Step
In [3]: dataset
localhost:8889/notebooks/Classification_With_Decision_Tree_MarketingData.ipynb 1/9
12/4/24, 12:08 PM Classification_With_Decision_Tree_MarketingData - Jupyter Notebook
In [4]: dataset.describe()
In [5]: # visualize the relationship between the features and the response using scatt
import seaborn as sns
sns.pairplot(dataset, x_vars=['youtube','facebook','newspaper'], y_vars='sales
C:\Users\PC\Anaconda3\lib\site-packages\seaborn\axisgrid.py:2065: UserWarnin
g: The `size` parameter has been renamed to `height`; pleaes update your cod
e.
warnings.warn(msg, UserWarning)
In [6]: dataset.corr()
localhost:8889/notebooks/Classification_With_Decision_Tree_MarketingData.ipynb 2/9
12/4/24, 12:08 PM Classification_With_Decision_Tree_MarketingData - Jupyter Notebook
In [59]: dataset
In [9]: dataset.groupby('sale_label').size()
Out[9]: sale_label
Low 22
Medium 119
High 59
dtype: int64
localhost:8889/notebooks/Classification_With_Decision_Tree_MarketingData.ipynb 3/9
12/4/24, 12:08 PM Classification_With_Decision_Tree_MarketingData - Jupyter Notebook
In [11]: #Split data into training and test datasets (training will be based on 70% of
from sklearn.model_selection import train_test_split
# Split dataset into train, test and validation sets
array = dataset.values
X = array[:,0:3] #Features
y = array[:,3] #Label|Target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, rando
localhost:8889/notebooks/Classification_With_Decision_Tree_MarketingData.ipynb 4/9
12/4/24, 12:08 PM Classification_With_Decision_Tree_MarketingData - Jupyter Notebook
In [13]: #X_train
y_train
localhost:8889/notebooks/Classification_With_Decision_Tree_MarketingData.ipynb 5/9
12/4/24, 12:08 PM Classification_With_Decision_Tree_MarketingData - Jupyter Notebook
0.85
[[ 9 0 3]
[ 0 6 2]
[ 2 2 36]]
precision recall f1-score support
accuracy 0.85 60
macro avg 0.82 0.80 0.81 60
weighted avg 0.85 0.85 0.85 60
In [17]: new_ads=pd.DataFrame({'youtube':[120,35],'facebook':[65,50],'newspaper':[25,20
In [18]: new_ads
0 120 65 25
1 35 50 20
In [19]: sale_pred=decision_tree.predict(new_ads)
sale_pred
0 120 65 25 High
1 35 50 20 Medium
localhost:8889/notebooks/Classification_With_Decision_Tree_MarketingData.ipynb 6/9
12/4/24, 12:08 PM Classification_With_Decision_Tree_MarketingData - Jupyter Notebook
['Medium']
In [25]: target
localhost:8889/notebooks/Classification_With_Decision_Tree_MarketingData.ipynb 7/9
12/4/24, 12:08 PM Classification_With_Decision_Tree_MarketingData - Jupyter Notebook
Out[27]:
Out[28]: True
localhost:8889/notebooks/Classification_With_Decision_Tree_MarketingData.ipynb 8/9
12/4/24, 12:08 PM Classification_With_Decision_Tree_MarketingData - Jupyter Notebook
In [ ]:
localhost:8889/notebooks/Classification_With_Decision_Tree_MarketingData.ipynb 9/9