2021BCS0103
2021BCS0103
2021BCS0103
data = pd.DataFrame({
'Study Hours':[3, 5, 8, 2, 6, 9, 4],
'Previous Exam Scores':[70, 65, 80, 50, 75, 85, 60],
'Result':['Fail','Fail','Pass','Fail','Pass','Pass','Fail']
})
data.head()
DecisionTreeClassifier(max_depth=3)
actual_depth_3 = tree_depth_3.get_depth()
print(f"The actual depth of the decision tree with depth 3:
{actual_depth_3}")
y_pred_depth_3 = tree_depth_3.predict(x_test)
print(y_pred_depth_3)
['Fail' 'Fail']
1.0
0.0
/usr/local/lib/python3.10/dist-packages/numpy/lib/arraysetops.py:608:
FutureWarning: elementwise comparison failed; returning scalar
instead, but in the future will perform elementwise comparison
mask &= (ar1 != a)
/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classificatio
n.py:1344: UndefinedMetricWarning: Precision is ill-defined and being
set to 0.0 due to no predicted samples. Use `zero_division` parameter
to control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
0.0
/usr/local/lib/python3.10/dist-packages/numpy/lib/arraysetops.py:608:
FutureWarning: elementwise comparison failed; returning scalar
instead, but in the future will perform elementwise comparison
mask &= (ar1 != a)
/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classificatio
n.py:1344: UndefinedMetricWarning: Recall is ill-defined and being set
to 0.0 due to no true samples. Use `zero_division` parameter to
control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
DecisionTreeClassifier(max_depth=5)
actual_depth_5 = tree_depth_5.get_depth()
print(f"The actual depth of the decision tree with depth 5:
{actual_depth_5}")
['Fail' 'Fail']
1.0
0.0
/usr/local/lib/python3.10/dist-packages/numpy/lib/arraysetops.py:608:
FutureWarning: elementwise comparison failed; returning scalar
instead, but in the future will perform elementwise comparison
mask &= (ar1 != a)
/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classificatio
n.py:1344: UndefinedMetricWarning: Precision is ill-defined and being
set to 0.0 due to no predicted samples. Use `zero_division` parameter
to control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
0.0
/usr/local/lib/python3.10/dist-packages/numpy/lib/arraysetops.py:608:
FutureWarning: elementwise comparison failed; returning scalar
instead, but in the future will perform elementwise comparison
mask &= (ar1 != a)
/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classificatio
n.py:1344: UndefinedMetricWarning: Recall is ill-defined and being set
to 0.0 due to no true samples. Use `zero_division` parameter to
control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
Analysis
-For the given dataset, both the trees constructed hhas its actual depth as 1. Therefore, there is
no difference in the performance of the decision tree with max-depth of 3 and the decision tree
with max- depth of 5.
-Since the size of the dataset is very small. Therefore, the chances of dataset to face overfitting
is very high.
-To analyse about the optimal depth of tree we should increase the size of the dataset.