Skip to content

Commit f21036b

Browse files
authored
Add files via upload
1 parent a98d2fd commit f21036b

File tree

2 files changed

+266
-0
lines changed

2 files changed

+266
-0
lines changed

CART_Project2/CART.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed Aug 1 20:55:39 2018
4+
5+
@author: wzy
6+
"""
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
"""
11+
函数说明:加载数据
12+
13+
Parameters:
14+
fileName - 文件名
15+
16+
Returns:
17+
dataMat - 数据矩阵
18+
19+
Modify:
20+
2018-08-01
21+
"""
22+
def loadDataSet(fileName):
23+
dataMat = []
24+
fr = open(fileName)
25+
for line in fr.readlines():
26+
curLine = line.strip().split('\t')
27+
# 转换为float类型
28+
# map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回。
29+
fltLine = list(map(float, curLine))
30+
dataMat.append(fltLine)
31+
return dataMat
32+
33+
34+
"""
35+
函数说明:绘制数据集
36+
37+
Parameters:
38+
fileName - 文件名
39+
40+
Returns:
41+
None
42+
43+
Modify:
44+
2018-08-01
45+
"""
46+
def plotDataSet(filename):
47+
dataMat = loadDataSet(filename)
48+
n = len(dataMat)
49+
xcord = []
50+
ycord = []
51+
# 样本点
52+
for i in range(n):
53+
xcord.append(dataMat[i][1])
54+
ycord.append(dataMat[i][2])
55+
fig = plt.figure()
56+
ax = fig.add_subplot(111)
57+
# 绘制样本点
58+
ax.scatter(xcord, ycord, s=20, c='blue', alpha=.5)
59+
plt.title('DataSet')
60+
plt.xlabel('X')
61+
plt.show()
62+
63+
64+
if __name__ == '__main__':
65+
filename = 'ex0.txt'
66+
plotDataSet(filename)

CART_Project2/ex0.txt

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
1.000000 0.409175 1.883180
2+
1.000000 0.182603 0.063908
3+
1.000000 0.663687 3.042257
4+
1.000000 0.517395 2.305004
5+
1.000000 0.013643 -0.067698
6+
1.000000 0.469643 1.662809
7+
1.000000 0.725426 3.275749
8+
1.000000 0.394350 1.118077
9+
1.000000 0.507760 2.095059
10+
1.000000 0.237395 1.181912
11+
1.000000 0.057534 0.221663
12+
1.000000 0.369820 0.938453
13+
1.000000 0.976819 4.149409
14+
1.000000 0.616051 3.105444
15+
1.000000 0.413700 1.896278
16+
1.000000 0.105279 -0.121345
17+
1.000000 0.670273 3.161652
18+
1.000000 0.952758 4.135358
19+
1.000000 0.272316 0.859063
20+
1.000000 0.303697 1.170272
21+
1.000000 0.486698 1.687960
22+
1.000000 0.511810 1.979745
23+
1.000000 0.195865 0.068690
24+
1.000000 0.986769 4.052137
25+
1.000000 0.785623 3.156316
26+
1.000000 0.797583 2.950630
27+
1.000000 0.081306 0.068935
28+
1.000000 0.659753 2.854020
29+
1.000000 0.375270 0.999743
30+
1.000000 0.819136 4.048082
31+
1.000000 0.142432 0.230923
32+
1.000000 0.215112 0.816693
33+
1.000000 0.041270 0.130713
34+
1.000000 0.044136 -0.537706
35+
1.000000 0.131337 -0.339109
36+
1.000000 0.463444 2.124538
37+
1.000000 0.671905 2.708292
38+
1.000000 0.946559 4.017390
39+
1.000000 0.904176 4.004021
40+
1.000000 0.306674 1.022555
41+
1.000000 0.819006 3.657442
42+
1.000000 0.845472 4.073619
43+
1.000000 0.156258 0.011994
44+
1.000000 0.857185 3.640429
45+
1.000000 0.400158 1.808497
46+
1.000000 0.375395 1.431404
47+
1.000000 0.885807 3.935544
48+
1.000000 0.239960 1.162152
49+
1.000000 0.148640 -0.227330
50+
1.000000 0.143143 -0.068728
51+
1.000000 0.321582 0.825051
52+
1.000000 0.509393 2.008645
53+
1.000000 0.355891 0.664566
54+
1.000000 0.938633 4.180202
55+
1.000000 0.348057 0.864845
56+
1.000000 0.438898 1.851174
57+
1.000000 0.781419 2.761993
58+
1.000000 0.911333 4.075914
59+
1.000000 0.032469 0.110229
60+
1.000000 0.499985 2.181987
61+
1.000000 0.771663 3.152528
62+
1.000000 0.670361 3.046564
63+
1.000000 0.176202 0.128954
64+
1.000000 0.392170 1.062726
65+
1.000000 0.911188 3.651742
66+
1.000000 0.872288 4.401950
67+
1.000000 0.733107 3.022888
68+
1.000000 0.610239 2.874917
69+
1.000000 0.732739 2.946801
70+
1.000000 0.714825 2.893644
71+
1.000000 0.076386 0.072131
72+
1.000000 0.559009 1.748275
73+
1.000000 0.427258 1.912047
74+
1.000000 0.841875 3.710686
75+
1.000000 0.558918 1.719148
76+
1.000000 0.533241 2.174090
77+
1.000000 0.956665 3.656357
78+
1.000000 0.620393 3.522504
79+
1.000000 0.566120 2.234126
80+
1.000000 0.523258 1.859772
81+
1.000000 0.476884 2.097017
82+
1.000000 0.176408 0.001794
83+
1.000000 0.303094 1.231928
84+
1.000000 0.609731 2.953862
85+
1.000000 0.017774 -0.116803
86+
1.000000 0.622616 2.638864
87+
1.000000 0.886539 3.943428
88+
1.000000 0.148654 -0.328513
89+
1.000000 0.104350 -0.099866
90+
1.000000 0.116868 -0.030836
91+
1.000000 0.516514 2.359786
92+
1.000000 0.664896 3.212581
93+
1.000000 0.004327 0.188975
94+
1.000000 0.425559 1.904109
95+
1.000000 0.743671 3.007114
96+
1.000000 0.935185 3.845834
97+
1.000000 0.697300 3.079411
98+
1.000000 0.444551 1.939739
99+
1.000000 0.683753 2.880078
100+
1.000000 0.755993 3.063577
101+
1.000000 0.902690 4.116296
102+
1.000000 0.094491 -0.240963
103+
1.000000 0.873831 4.066299
104+
1.000000 0.991810 4.011834
105+
1.000000 0.185611 0.077710
106+
1.000000 0.694551 3.103069
107+
1.000000 0.657275 2.811897
108+
1.000000 0.118746 -0.104630
109+
1.000000 0.084302 0.025216
110+
1.000000 0.945341 4.330063
111+
1.000000 0.785827 3.087091
112+
1.000000 0.530933 2.269988
113+
1.000000 0.879594 4.010701
114+
1.000000 0.652770 3.119542
115+
1.000000 0.879338 3.723411
116+
1.000000 0.764739 2.792078
117+
1.000000 0.504884 2.192787
118+
1.000000 0.554203 2.081305
119+
1.000000 0.493209 1.714463
120+
1.000000 0.363783 0.885854
121+
1.000000 0.316465 1.028187
122+
1.000000 0.580283 1.951497
123+
1.000000 0.542898 1.709427
124+
1.000000 0.112661 0.144068
125+
1.000000 0.816742 3.880240
126+
1.000000 0.234175 0.921876
127+
1.000000 0.402804 1.979316
128+
1.000000 0.709423 3.085768
129+
1.000000 0.867298 3.476122
130+
1.000000 0.993392 3.993679
131+
1.000000 0.711580 3.077880
132+
1.000000 0.133643 -0.105365
133+
1.000000 0.052031 -0.164703
134+
1.000000 0.366806 1.096814
135+
1.000000 0.697521 3.092879
136+
1.000000 0.787262 2.987926
137+
1.000000 0.476710 2.061264
138+
1.000000 0.721417 2.746854
139+
1.000000 0.230376 0.716710
140+
1.000000 0.104397 0.103831
141+
1.000000 0.197834 0.023776
142+
1.000000 0.129291 -0.033299
143+
1.000000 0.528528 1.942286
144+
1.000000 0.009493 -0.006338
145+
1.000000 0.998533 3.808753
146+
1.000000 0.363522 0.652799
147+
1.000000 0.901386 4.053747
148+
1.000000 0.832693 4.569290
149+
1.000000 0.119002 -0.032773
150+
1.000000 0.487638 2.066236
151+
1.000000 0.153667 0.222785
152+
1.000000 0.238619 1.089268
153+
1.000000 0.208197 1.487788
154+
1.000000 0.750921 2.852033
155+
1.000000 0.183403 0.024486
156+
1.000000 0.995608 3.737750
157+
1.000000 0.151311 0.045017
158+
1.000000 0.126804 0.001238
159+
1.000000 0.983153 3.892763
160+
1.000000 0.772495 2.819376
161+
1.000000 0.784133 2.830665
162+
1.000000 0.056934 0.234633
163+
1.000000 0.425584 1.810782
164+
1.000000 0.998709 4.237235
165+
1.000000 0.707815 3.034768
166+
1.000000 0.413816 1.742106
167+
1.000000 0.217152 1.169250
168+
1.000000 0.360503 0.831165
169+
1.000000 0.977989 3.729376
170+
1.000000 0.507953 1.823205
171+
1.000000 0.920771 4.021970
172+
1.000000 0.210542 1.262939
173+
1.000000 0.928611 4.159518
174+
1.000000 0.580373 2.039114
175+
1.000000 0.841390 4.101837
176+
1.000000 0.681530 2.778672
177+
1.000000 0.292795 1.228284
178+
1.000000 0.456918 1.736620
179+
1.000000 0.134128 -0.195046
180+
1.000000 0.016241 -0.063215
181+
1.000000 0.691214 3.305268
182+
1.000000 0.582002 2.063627
183+
1.000000 0.303102 0.898840
184+
1.000000 0.622598 2.701692
185+
1.000000 0.525024 1.992909
186+
1.000000 0.996775 3.811393
187+
1.000000 0.881025 4.353857
188+
1.000000 0.723457 2.635641
189+
1.000000 0.676346 2.856311
190+
1.000000 0.254625 1.352682
191+
1.000000 0.488632 2.336459
192+
1.000000 0.519875 2.111651
193+
1.000000 0.160176 0.121726
194+
1.000000 0.609483 3.264605
195+
1.000000 0.531881 2.103446
196+
1.000000 0.321632 0.896855
197+
1.000000 0.845148 4.220850
198+
1.000000 0.012003 -0.217283
199+
1.000000 0.018883 -0.300577
200+
1.000000 0.071476 0.006014

0 commit comments

Comments
 (0)