Skip to content
FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS
Close
Beyond Knowledge Innovation

Beyond Knowledge Innovation

Where Data Unveils Possibilities

  • Home
  • AI & ML Insights
  • Machine Learning
    • Supervised Learning
      • Introduction
      • Regression
      • Classification
    • Unsupervised Learning
      • Introduction
      • Clustering
      • Association
      • Dimensionality Reduction
    • Reinforcement Learning
    • Generative AI
  • Knowledge Base
    • Introduction To Python
    • Introduction To Data
    • Introduction to EDA
  • References
HomeImplementationSupervised LearningClassificationPre-pruning Decision Tree – depth restricted
Classification Knowledge Base

Pre-pruning Decision Tree – depth restricted

March 8, 2024March 8, 2024CEO 396 views

In general, the deeper you allow your tree to grow, the more complex your model will become because you will have more splits and it captures more information about the data and this is one of the root causes of overfitting.

We can limit the tree with max_depth of tree:

from google.colab import drive
drive.mount('/content/drive')

functions_path = '/content/drive/MyDrive/Lib/'
%run {functions_path}myfunctions.ipynb

clf = DecisionTreeClassifier(criterion='gini', max_depth=3, random_state=1)
clf.fit(X_train, y_train)

# review performance of the tree
make_confusion_matrix(clf, X_test, y_test)
get_accuracy_and_recall_score(clf, X_train, X_test, y_train, y_test)
get_feature_importances_and_visualize(clf, X_train)
decision tree, max_depth, pre-pruning

Post navigation

Previous Post
Previous post: Feature Importance in Decision Tree
Next Post
Next post: Pre-pruning Decision Tree – GridSearch for Hyperparameter tuning

You Might Also Like

No image
BaggingClassifier from Scikit-Learn
April 7, 2024 Comments Off on BaggingClassifier from Scikit-Learn
No image
Post-pruning Decision Tree with Cost Complexity Parameter…
March 8, 2024 Comments Off on Post-pruning Decision Tree with Cost Complexity Parameter ccp_alpha
No image
Pre-pruning Decision Tree – GridSearch for Hyperparameter…
March 8, 2024 Comments Off on Pre-pruning Decision Tree – GridSearch for Hyperparameter tuning
No image
Feature Importance in Decision Tree
March 7, 2024 Comments Off on Feature Importance in Decision Tree
No image
Visualizing the Decision Tree
March 7, 2024 Comments Off on Visualizing the Decision Tree
  • Recent
  • Popular
  • Random
  • No image
    2 years ago Low-Rank Factorization
  • No image
    2 years ago Perturbation Test for a Regression Model
  • No image
    2 years ago Calibration Curve for Classification Models
  • No image
    March 15, 20240Single linkage hierarchical clustering
  • No image
    April 17, 20240XGBoost (eXtreme Gradient Boosting)
  • No image
    April 17, 20240Gradient Boosting
  • No image
    March 3, 2024Python warnings module
  • No image
    January 19, 2024NumPy View array vs. Copy array
  • No image
    March 11, 2024What is Silhouette Coefficient
  • Implementation (55)
    • EDA (4)
    • Neural Networks (10)
    • Supervised Learning (26)
      • Classification (17)
      • Linear Regression (8)
    • Unsupervised Learning (11)
      • Clustering (8)
      • Dimensionality Reduction (3)
  • Knowledge Base (44)
    • Python (27)
    • Statistics (6)
May 2026
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031
« Oct    

We are on

FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS

Subscribe

© 2026 Beyond Knowledge Innovation
FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS