Decision Tree vs Random Forest Comparison
Using the notes' own customer-purchase dataset, train both a DecisionTreeClassifier and a RandomForestClassifier, and compare their predictions for a given new customer.
Approach: fit both models (with a fixed random_state for reproducibility) on the same small dataset, then predict for the given [age, income] pair with each.
Input: Two lines: a customer's age, then their income.
Output: Two lines: the Decision Tree's prediction, then the Random Forest's prediction (0 or 1).
30 55000
Decision Tree: 0 Random Forest: 0
- 18 <= age <= 100
- 0 <= income <= 10000000
Hint 1
DecisionTreeClassifier(random_state=42) and RandomForestClassifier(n_estimators=100, random_state=42) — set random_state on both so results are reproducible.
Hint 2
Both models are trained the exact same way: model.fit(features, buys_product).
Hint 3
model.predict([[age, income]]) returns a list with one prediction — take element [0].
Both models are trained on the identical small dataset from the notes, each with a fixed random_state so their internal randomness (tree-building order, bootstrap sampling for the forest) is reproducible. Calling .predict([[age, income]]) on each trained model gives its classification for the new customer — printing both side by side is exactly the "comparison" the problem asks for.