File size: 1,168 Bytes
b12e4cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
 "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
}