{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Assignment. 자동차 평가 데이터에 대한 EDA 및 Decision Tree를 활용한 예측\n", "- 데이터 집합 소스\n", " - 설명: http://archive.ics.uci.edu/ml/datasets/Car+Evaluation\n", " - Features\n", " - buying (자동차 가격): vhigh, high, med, low.\n", " - maint (유지보수 가격): vhigh, high, med, low.\n", " - doors (자동차 문의 개수): 2, 3, 4, 5more.\n", " - persons (자동차 안에 탈 수 있는 사람 인원): 2, 4, more.\n", " - lug_boot (짐트렁크 크기): small, med, big.\n", " - safety (안전도): low, med, high.\n", " - Target \n", " - eval (평가만족도): unacc, acc, good, vgood\n", " - 모든 Attributes들을 Categorical 데이터로 취급해도 됨 \n", " - 데이터: http://archive.ics.uci.edu/ml/machine-learning-databases/car/car.data" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import urllib2\n", "from scipy import stats\n", "from pandas import Series, DataFrame\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "%matplotlib inline\n", "\n", "path = 'http://archive.ics.uci.edu/ml/machine-learning-databases/car/car.data'\n", "raw_csv = urllib2.urlopen(path)\n", "feature_names = ('buying', 'maint', 'doors', 'persons', \"log_boot\", \"safety\")\n", "target_name = 'eval'\n", "all_names = feature_names + (target_name,)\n", "df = pd.read_csv(raw_csv, names=all_names)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", " | buying | \n", "maint | \n", "doors | \n", "persons | \n", "log_boot | \n", "safety | \n", "eval | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "2 | \n", "small | \n", "low | \n", "unacc | \n", "
1 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "2 | \n", "small | \n", "med | \n", "unacc | \n", "
2 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "2 | \n", "small | \n", "high | \n", "unacc | \n", "
3 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "2 | \n", "med | \n", "low | \n", "unacc | \n", "
4 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "2 | \n", "med | \n", "med | \n", "unacc | \n", "
5 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "2 | \n", "med | \n", "high | \n", "unacc | \n", "
6 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "2 | \n", "big | \n", "low | \n", "unacc | \n", "
7 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "2 | \n", "big | \n", "med | \n", "unacc | \n", "
8 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "2 | \n", "big | \n", "high | \n", "unacc | \n", "
9 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "4 | \n", "small | \n", "low | \n", "unacc | \n", "
10 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "4 | \n", "small | \n", "med | \n", "unacc | \n", "
11 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "4 | \n", "small | \n", "high | \n", "unacc | \n", "
12 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "4 | \n", "med | \n", "low | \n", "unacc | \n", "
13 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "4 | \n", "med | \n", "med | \n", "unacc | \n", "
14 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "4 | \n", "med | \n", "high | \n", "unacc | \n", "
15 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "4 | \n", "big | \n", "low | \n", "unacc | \n", "
16 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "4 | \n", "big | \n", "med | \n", "unacc | \n", "
17 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "4 | \n", "big | \n", "high | \n", "unacc | \n", "
18 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "more | \n", "small | \n", "low | \n", "unacc | \n", "
19 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "more | \n", "small | \n", "med | \n", "unacc | \n", "
20 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "more | \n", "small | \n", "high | \n", "unacc | \n", "
21 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "more | \n", "med | \n", "low | \n", "unacc | \n", "
22 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "more | \n", "med | \n", "med | \n", "unacc | \n", "
23 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "more | \n", "med | \n", "high | \n", "unacc | \n", "
24 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "more | \n", "big | \n", "low | \n", "unacc | \n", "
25 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "more | \n", "big | \n", "med | \n", "unacc | \n", "
26 | \n", "vhigh | \n", "vhigh | \n", "2 | \n", "more | \n", "big | \n", "high | \n", "unacc | \n", "
27 | \n", "vhigh | \n", "vhigh | \n", "3 | \n", "2 | \n", "small | \n", "low | \n", "unacc | \n", "
28 | \n", "vhigh | \n", "vhigh | \n", "3 | \n", "2 | \n", "small | \n", "med | \n", "unacc | \n", "
29 | \n", "vhigh | \n", "vhigh | \n", "3 | \n", "2 | \n", "small | \n", "high | \n", "unacc | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
1698 | \n", "low | \n", "low | \n", "4 | \n", "more | \n", "big | \n", "low | \n", "unacc | \n", "
1699 | \n", "low | \n", "low | \n", "4 | \n", "more | \n", "big | \n", "med | \n", "good | \n", "
1700 | \n", "low | \n", "low | \n", "4 | \n", "more | \n", "big | \n", "high | \n", "vgood | \n", "
1701 | \n", "low | \n", "low | \n", "5more | \n", "2 | \n", "small | \n", "low | \n", "unacc | \n", "
1702 | \n", "low | \n", "low | \n", "5more | \n", "2 | \n", "small | \n", "med | \n", "unacc | \n", "
1703 | \n", "low | \n", "low | \n", "5more | \n", "2 | \n", "small | \n", "high | \n", "unacc | \n", "
1704 | \n", "low | \n", "low | \n", "5more | \n", "2 | \n", "med | \n", "low | \n", "unacc | \n", "
1705 | \n", "low | \n", "low | \n", "5more | \n", "2 | \n", "med | \n", "med | \n", "unacc | \n", "
1706 | \n", "low | \n", "low | \n", "5more | \n", "2 | \n", "med | \n", "high | \n", "unacc | \n", "
1707 | \n", "low | \n", "low | \n", "5more | \n", "2 | \n", "big | \n", "low | \n", "unacc | \n", "
1708 | \n", "low | \n", "low | \n", "5more | \n", "2 | \n", "big | \n", "med | \n", "unacc | \n", "
1709 | \n", "low | \n", "low | \n", "5more | \n", "2 | \n", "big | \n", "high | \n", "unacc | \n", "
1710 | \n", "low | \n", "low | \n", "5more | \n", "4 | \n", "small | \n", "low | \n", "unacc | \n", "
1711 | \n", "low | \n", "low | \n", "5more | \n", "4 | \n", "small | \n", "med | \n", "acc | \n", "
1712 | \n", "low | \n", "low | \n", "5more | \n", "4 | \n", "small | \n", "high | \n", "good | \n", "
1713 | \n", "low | \n", "low | \n", "5more | \n", "4 | \n", "med | \n", "low | \n", "unacc | \n", "
1714 | \n", "low | \n", "low | \n", "5more | \n", "4 | \n", "med | \n", "med | \n", "good | \n", "
1715 | \n", "low | \n", "low | \n", "5more | \n", "4 | \n", "med | \n", "high | \n", "vgood | \n", "
1716 | \n", "low | \n", "low | \n", "5more | \n", "4 | \n", "big | \n", "low | \n", "unacc | \n", "
1717 | \n", "low | \n", "low | \n", "5more | \n", "4 | \n", "big | \n", "med | \n", "good | \n", "
1718 | \n", "low | \n", "low | \n", "5more | \n", "4 | \n", "big | \n", "high | \n", "vgood | \n", "
1719 | \n", "low | \n", "low | \n", "5more | \n", "more | \n", "small | \n", "low | \n", "unacc | \n", "
1720 | \n", "low | \n", "low | \n", "5more | \n", "more | \n", "small | \n", "med | \n", "acc | \n", "
1721 | \n", "low | \n", "low | \n", "5more | \n", "more | \n", "small | \n", "high | \n", "good | \n", "
1722 | \n", "low | \n", "low | \n", "5more | \n", "more | \n", "med | \n", "low | \n", "unacc | \n", "
1723 | \n", "low | \n", "low | \n", "5more | \n", "more | \n", "med | \n", "med | \n", "good | \n", "
1724 | \n", "low | \n", "low | \n", "5more | \n", "more | \n", "med | \n", "high | \n", "vgood | \n", "
1725 | \n", "low | \n", "low | \n", "5more | \n", "more | \n", "big | \n", "low | \n", "unacc | \n", "
1726 | \n", "low | \n", "low | \n", "5more | \n", "more | \n", "big | \n", "med | \n", "good | \n", "
1727 | \n", "low | \n", "low | \n", "5more | \n", "more | \n", "big | \n", "high | \n", "vgood | \n", "
1728 rows × 7 columns
\n", "