In this ML Algorithms course tutorial, we are going to learn “Decision Tree Regression in detail. we covered it by practically and theoretical intuition.
- What is Decision Tree?
- What are decision trees used for?
- How do Decision trees work?
- What is Decision Tree Regression?
- What is Gini impurity, entropy, cost function for CART algorithm?
- What is decision tree diagram?
- What is the difference between decision tree and random forest?
- How to implement Decision Tree Regression in python using sklearn?
Decision Tree Regression Source Code
# -*- coding: utf-8 -*- """Decision Tree Regression.ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1-P0w3bewXTLPItdgVatdg8i5SzlIDX-L ## Business Problem - Predict the Price of Bangalore House Using Decision Tree Regression - Supervised Machine Learning Algorithm ### Load Libraries """ import pandas as pd """### Load Data""" path = r"https://drive.google.com/uc?export=download&id=1xxDtrZKfuWQfl-6KA9XEd_eatitNPnkB" df = pd.read_csv(path) df.head() """## Split Data""" X = df.drop('price', axis=1) y = df['price'] print('Shape of X = ', X.shape) print('Shape of y = ', y.shape) from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=51) print('Shape of X_train = ', X_train.shape) print('Shape of y_train = ', y_train.shape) print('Shape of X_test = ', X_test.shape) print('Shape of y_test = ', y_test.shape) """##Decision Tree Regression - ML Model Training""" from sklearn.tree import DecisionTreeRegressor regressor = DecisionTreeRegressor(criterion='mse') regressor.fit(X_train, y_train) regressor.score(X_test, y_test) """## Predict the value of Home""" X_test.iloc[-1, :] regressor.predict([X_test.iloc[-1, :]]) y_test.iloc[-1] pred = regressor.predict(X_test) pred y_test """Ab milenge next tutorial me,Tab tak ke liye SIKHATE SIKHATE kuch IMPLEMENT karte raho, Thank You.....-:)"""