Visualizing the Power of Machine Learning
A decision tree trained on the Iris dataset to classify flower species based on sepal and petal measurements.
A regression tree predicting house prices in Boston, using features like crime rate, number of rooms, and proximity to amenities.
Visualizing which features were most influential in making predictions for a given dataset, as determined by the decision tree.
A decision tree model to predict customer churn based on usage patterns, demographics, and service interactions.
Illustrating the concept of a Random Forest, an ensemble of multiple decision trees, for improved accuracy and robustness.
Using a decision tree for predicting future sales based on historical data, seasonality, and promotional activities.
A detailed view of a single decision tree's nodes and branches, showing how decisions are made at each split.
Exploring Gradient Boosting, another powerful ensemble technique that builds trees sequentially to correct errors.
# Example: Building a simple decision tree for classification
from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# Load dataset
iris = load_iris()
X, y = iris.data, iris.target
# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# Initialize and train the classifier
dtc = DecisionTreeClassifier(max_depth=3, random_state=42)
dtc.fit(X_train, y_train)
# Make predictions
y_pred = dtc.predict(X_test)
# Evaluate the model
accuracy = accuracy_score(y_test, y_pred)
print(f"Accuracy: {accuracy:.2f}")
# You can visualize the tree using libraries like graphviz or matplotlib
# from sklearn.tree import plot_tree
# import matplotlib.pyplot as plt
# plt.figure(figsize=(12, 8))
# plot_tree(dtc, feature_names=iris.feature_names, class_names=iris.target_names, filled=True)
# plt.show()