{ "cells": [ { "cell_type": "markdown", "id": "10d2cf4b", "metadata": {}, "source": [ "# Assignment 5: Decision Tree Classifier\n", "Train a decision tree classifier on a synthetic dataset of customer purchases.\n", "Predict whether a customer will buy based on age and income." ] }, { "cell_type": "code", "execution_count": null, "id": "10abdab6", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from sklearn.tree import DecisionTreeClassifier\n", "\n", "# Synthetic dataset\n", "data = {\n", " 'age': [25, 30, 35, 40],\n", " 'income': [50000, 60000, 55000, 70000],\n", " 'buy': [0, 1, 0, 1]\n", "}\n", "df = pd.DataFrame(data)\n", "\n", "# Train model\n", "X = df[['age', 'income']]\n", "y = df['buy']\n", "model = DecisionTreeClassifier()\n", "model.fit(X, y) # Error: Missing arguments, should be model.fit(X, y)\\n\",\n", "\n", "# Predict\\n\",\n", "print(model.predict([[30, 65000]]))" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }