In [1]:
import pandas as pd
import numpy as np
dadosBrutos = pd.read_csv('communities.data.csv', header=None)
dadosBrutos = dadosBrutos.replace(['?'], [''])
dadosBrutos
Out[1]:
0
1
2
3
4
5
6
7
8
9
...
118
119
120
121
122
123
124
125
126
127
0
8
Lakewoodcity
1
0.19
0.33
0.02
0.90
0.12
...
0.12
0.26
0.20
0.06
0.04
0.9
0.5
0.32
0.14
0.20
1
53
Tukwilacity
1
0.00
0.16
0.12
0.74
0.45
...
0.02
0.12
0.45
0.00
0.67
2
24
Aberdeentown
1
0.00
0.42
0.49
0.56
0.17
...
0.01
0.21
0.02
0.00
0.43
3
34
5
81440
Willingborotownship
1
0.04
0.77
1.00
0.08
0.12
...
0.02
0.39
0.28
0.00
0.12
4
42
95
6096
Bethlehemtownship
1
0.01
0.55
0.02
0.95
0.09
...
0.04
0.09
0.02
0.00
0.03
5
6
SouthPasadenacity
1
0.02
0.28
0.06
0.54
1.00
...
0.01
0.58
0.10
0.00
0.14
6
44
7
41500
Lincolntown
1
0.01
0.39
0.00
0.98
0.06
...
0.05
0.08
0.06
0.00
0.03
7
6
Selmacity
1
0.01
0.74
0.03
0.46
0.20
...
0.01
0.33
0.00
0.00
0.55
8
21
Hendersoncity
1
0.03
0.34
0.20
0.84
0.02
...
0.04
0.17
0.04
0.00
0.53
9
29
Claytoncity
1
0.01
0.40
0.06
0.87
0.30
...
0.00
0.47
0.11
0.00
0.15
10
6
DalyCitycity
1
0.13
0.71
0.15
0.07
1.00
...
0.02
1.00
1.00
0.00
0.24
11
36
RockvilleCentrevillage
1
0.02
0.46
0.08
0.91
0.07
...
0.01
0.63
1.00
0.00
0.08
12
25
21
44105
Needhamtown
1
0.03
0.47
0.01
0.96
0.13
...
0.03
0.18
0.59
0.00
0.06
13
55
87
30075
GrandChutetown
1
0.01
0.44
0.00
0.98
0.04
...
0.08
0.04
0.00
0.00
0.09
14
6
DanaPointcity
1
0.04
0.36
0.01
0.85
0.14
...
0.02
0.40
0.15
0.00
0.21
15
19
187
91370
FortDodgecity
1
0.03
0.34
0.06
0.93
0.03
...
0.04
0.15
0.04
0.00
0.30
16
36
1
1000
Albanycity
1
0.15
0.31
0.40
0.63
0.14
...
0.06
0.39
0.84
0.06
0.06
0.91
0.5
0.88
0.26
0.49
17
34
27
17650
Denvilletownship
1
0.01
0.53
0.01
0.94
0.20
...
0.03
0.09
0.21
0.00
0.07
18
18
Valparaisocity
1
0.02
0.47
0.01
0.97
0.07
...
0.03
0.20
0.07
0.00
0.15
19
42
129
66376
Rostravertownship
1
0.00
0.41
0.05
0.96
0.01
...
0.09
0.03
0.05
0.00
0.03
20
6
Modestocity
1
0.25
0.54
0.05
0.71
0.48
...
0.09
0.46
0.05
0.09
0.05
0.88
0.5
0.76
0.13
0.34
21
12
31
Jacksonvillecity
1
1.00
0.42
0.47
0.59
0.12
...
1.00
0.07
0.15
1
0.35
0.73
0
0.31
0.21
0.69
22
41
KlamathFallscity
1
0.01
0.34
0.02
0.87
0.07
...
0.05
0.09
0.06
0.00
0.21
23
19
193
93926
SiouxCitycity
1
0.11
0.43
0.04
0.89
0.09
...
0.16
0.12
0.07
0.04
0.01
0.81
1
0.56
0.09
0.63
24
6
Delanocity
1
0.02
0.96
0.05
0.00
1.00
...
0.02
0.22
0.02
0.00
0.31
25
8
Goldencity
1
0.00
0.33
0.02
0.91
0.16
...
0.02
0.15
0.16
0.00
0.12
26
6
Gardenacity
1
0.06
0.49
0.46
0.00
1.00
...
0.01
0.79
0.21
0.00
0.84
27
39
29
61798
Perrytownship
1
0.01
0.37
0.01
0.99
0.02
...
0.04
0.09
0.00
0.00
0.10
28
54
Beckleycity
1
0.01
0.27
0.43
0.64
0.08
...
0.02
0.17
0.00
0.00
0.49
29
9
7
22490
EastHamptontown
1
0.00
0.50
0.01
0.98
0.02
...
0.10
0.02
0.08
0.00
0.02
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
1964
36
119
49121
MountVernoncity
10
0.09
0.45
1.00
0.08
0.11
...
0.01
1.00
1.00
0.00
0.60
1965
18
97
Indianapoliscity
10
1.00
0.36
0.44
0.64
0.06
...
1.00
0.17
0.18
0.45
0.19
0.5
0.5
0.44
0.21
0.69
1966
6
RedwoodCitycity
10
0.09
0.41
0.07
0.74
0.39
...
0.05
0.29
0.22
0.00
0.30
1967
25
17
76135
Westfordtown
10
0.01
0.66
0.00
0.97
0.10
...
0.09
0.04
0.04
0.00
0.04
1968
34
25
62430
RedBankborough
10
0.00
0.24
0.51
0.53
0.11
...
0.00
0.50
0.49
0.00
0.19
1969
6
SanFranciscocity
10
1.00
0.29
0.21
0.29
1.00
...
0.13
1.00
1.00
0.53
0.62
0.64
0.5
0.64
0.35
0.75
1970
45
Caycecity
10
0.00
0.37
0.38
0.69
0.04
...
0.02
0.10
0.08
0.00
0.53
1971
1
Decaturcity
10
0.06
0.39
0.32
0.73
0.04
...
0.14
0.09
0.01
0.00
0.22
1972
6
Redlandscity
10
0.08
0.49
0.07
0.69
0.27
...
0.07
0.21
0.02
0.00
0.30
1973
39
Englewoodcity
10
0.00
0.38
0.03
0.97
0.04
...
0.01
0.18
0.10
0.00
0.04
1974
37
Tarborotown
10
0.00
0.41
0.62
0.51
0.02
...
0.02
0.10
0.00
0.00
0.52
1975
53
Kirklandcity
10
0.05
0.27
0.03
0.89
0.27
...
0.03
0.31
0.34
0.00
0.09
1976
25
17
1605
Arlingtontown
10
0.06
0.29
0.03
0.93
0.18
...
0.01
0.72
0.94
0.00
0.08
1977
47
Maryvillecity
10
0.01
0.35
0.06
0.94
0.06
...
0.04
0.12
0.01
0.00
0.25
1978
9
1
4720
Betheltown
10
0.01
0.54
0.02
0.94
0.13
...
0.05
0.09
0.14
0.00
0.04
1979
34
39
61530
Rahwaycity
10
0.02
0.43
0.39
0.63
0.15
...
0.01
0.53
0.43
0.00
0.16
1980
25
5
69170
Tauntoncity
10
0.06
0.43
0.04
0.93
0.03
...
0.13
0.09
0.11
0.00
0.28
1981
9
9
35650
Hamdentown
10
0.07
0.38
0.17
0.84
0.11
...
0.09
0.13
0.17
0.02
0.01
0.72
0
0.62
0.15
0.07
1982
42
133
73168
SpringGardentownship
10
0.00
0.47
0.02
0.98
0.03
...
0.02
0.14
0.04
0.00
0.03
1983
13
ForestParkcity
10
0.01
0.45
0.37
0.65
0.15
...
0.02
0.16
0.13
0.00
0.56
1984
39
95
48342
Maumeecity
10
0.01
0.43
0.01
0.98
0.03
...
0.02
0.15
0.06
0.00
0.14
1985
1
AlexanderCitycity
10
0.01
0.41
0.55
0.57
0.01
...
0.11
0.03
0.01
0.00
0.14
1986
9
3
70550
Southingtontown
10
0.05
0.52
0.02
0.97
0.04
...
0.10
0.09
0.03
0.00
0.02
1987
44
7
11800
Burrillvilletown
10
0.01
0.65
0.00
1.00
0.01
...
0.16
0.02
0.02
0.00
0.04
1988
28
Columbuscity
10
0.02
0.41
1.00
0.21
0.02
...
0.03
0.17
0.02
0.00
0.19
1989
12
TempleTerracecity
10
0.01
0.40
0.10
0.87
0.12
...
0.01
0.28
0.05
0.00
0.09
1990
6
Seasidecity
10
0.05
0.96
0.46
0.28
0.83
...
0.02
0.37
0.20
0.00
0.45
1991
9
9
80070
Waterburytown
10
0.16
0.37
0.25
0.69
0.04
...
0.08
0.32
0.18
0.08
0.06
0.78
0
0.91
0.28
0.23
1992
25
17
72600
Walthamcity
10
0.08
0.51
0.06
0.87
0.22
...
0.03
0.38
0.33
0.02
0.02
0.79
0
0.22
0.18
0.19
1993
6
Ontariocity
10
0.20
0.78
0.14
0.46
0.24
...
0.11
0.30
0.05
0.08
0.04
0.73
0.5
1.00
0.13
0.48
1994 rows × 128 columns
In [2]:
Z = dadosBrutos.iloc[:, 3:4]
print Z
3
0 Lakewoodcity
1 Tukwilacity
2 Aberdeentown
3 Willingborotownship
4 Bethlehemtownship
5 SouthPasadenacity
6 Lincolntown
7 Selmacity
8 Hendersoncity
9 Claytoncity
10 DalyCitycity
11 RockvilleCentrevillage
12 Needhamtown
13 GrandChutetown
14 DanaPointcity
15 FortDodgecity
16 Albanycity
17 Denvilletownship
18 Valparaisocity
19 Rostravertownship
20 Modestocity
21 Jacksonvillecity
22 KlamathFallscity
23 SiouxCitycity
24 Delanocity
25 Goldencity
26 Gardenacity
27 Perrytownship
28 Beckleycity
29 EastHamptontown
... ...
1964 MountVernoncity
1965 Indianapoliscity
1966 RedwoodCitycity
1967 Westfordtown
1968 RedBankborough
1969 SanFranciscocity
1970 Caycecity
1971 Decaturcity
1972 Redlandscity
1973 Englewoodcity
1974 Tarborotown
1975 Kirklandcity
1976 Arlingtontown
1977 Maryvillecity
1978 Betheltown
1979 Rahwaycity
1980 Tauntoncity
1981 Hamdentown
1982 SpringGardentownship
1983 ForestParkcity
1984 Maumeecity
1985 AlexanderCitycity
1986 Southingtontown
1987 Burrillvilletown
1988 Columbuscity
1989 TempleTerracecity
1990 Seasidecity
1991 Waterburytown
1992 Walthamcity
1993 Ontariocity
[1994 rows x 1 columns]
In [3]:
dadosBrutos.drop(dadosBrutos.columns[[3]], axis=1, inplace=True)
X = dadosBrutos.iloc[:, :-1]
Y = dadosBrutos.iloc[ :, -1:]
In [9]:
X
Out[9]:
0
1
2
4
5
6
7
8
9
10
...
117
118
119
120
121
122
123
124
125
126
0
8
1
0.19
0.33
0.02
0.90
0.12
0.17
...
0.29
0.12
0.26
0.20
0.06
0.04
0.9
0.5
0.32
0.14
1
53
1
0.00
0.16
0.12
0.74
0.45
0.07
...
0.02
0.12
0.45
0.00
2
24
1
0.00
0.42
0.49
0.56
0.17
0.04
...
0.01
0.21
0.02
0.00
3
34
5
81440
1
0.04
0.77
1.00
0.08
0.12
0.10
...
0.02
0.39
0.28
0.00
4
42
95
6096
1
0.01
0.55
0.02
0.95
0.09
0.05
...
0.04
0.09
0.02
0.00
5
6
1
0.02
0.28
0.06
0.54
1.00
0.25
...
0.01
0.58
0.10
0.00
6
44
7
41500
1
0.01
0.39
0.00
0.98
0.06
0.02
...
0.05
0.08
0.06
0.00
7
6
1
0.01
0.74
0.03
0.46
0.20
1.00
...
0.01
0.33
0.00
0.00
8
21
1
0.03
0.34
0.20
0.84
0.02
0.00
...
0.04
0.17
0.04
0.00
9
29
1
0.01
0.40
0.06
0.87
0.30
0.03
...
0.00
0.47
0.11
0.00
10
6
1
0.13
0.71
0.15
0.07
1.00
0.41
...
0.02
1.00
1.00
0.00
11
36
1
0.02
0.46
0.08
0.91
0.07
0.10
...
0.01
0.63
1.00
0.00
12
25
21
44105
1
0.03
0.47
0.01
0.96
0.13
0.02
...
0.03
0.18
0.59
0.00
13
55
87
30075
1
0.01
0.44
0.00
0.98
0.04
0.01
...
0.08
0.04
0.00
0.00
14
6
1
0.04
0.36
0.01
0.85
0.14
0.26
...
0.02
0.40
0.15
0.00
15
19
187
91370
1
0.03
0.34
0.06
0.93
0.03
0.03
...
0.04
0.15
0.04
0.00
16
36
1
1000
1
0.15
0.31
0.40
0.63
0.14
0.06
...
0.22
0.06
0.39
0.84
0.06
0.06
0.91
0.5
0.88
0.26
17
34
27
17650
1
0.01
0.53
0.01
0.94
0.20
0.03
...
0.03
0.09
0.21
0.00
18
18
1
0.02
0.47
0.01
0.97
0.07
0.02
...
0.03
0.20
0.07
0.00
19
42
129
66376
1
0.00
0.41
0.05
0.96
0.01
0.01
...
0.09
0.03
0.05
0.00
20
6
1
0.25
0.54
0.05
0.71
0.48
0.30
...
0.36
0.09
0.46
0.05
0.09
0.05
0.88
0.5
0.76
0.13
21
12
31
1
1.00
0.42
0.47
0.59
0.12
0.05
...
1
1.00
0.07
0.15
1
0.35
0.73
0
0.31
0.21
22
41
1
0.01
0.34
0.02
0.87
0.07
0.11
...
0.05
0.09
0.06
0.00
23
19
193
93926
1
0.11
0.43
0.04
0.89
0.09
0.06
...
0.29
0.16
0.12
0.07
0.04
0.01
0.81
1
0.56
0.09
24
6
1
0.02
0.96
0.05
0.00
1.00
1.00
...
0.02
0.22
0.02
0.00
25
8
1
0.00
0.33
0.02
0.91
0.16
0.09
...
0.02
0.15
0.16
0.00
26
6
1
0.06
0.49
0.46
0.00
1.00
0.43
...
0.01
0.79
0.21
0.00
27
39
29
61798
1
0.01
0.37
0.01
0.99
0.02
0.01
...
0.04
0.09
0.00
0.00
28
54
1
0.01
0.27
0.43
0.64
0.08
0.01
...
0.02
0.17
0.00
0.00
29
9
7
22490
1
0.00
0.50
0.01
0.98
0.02
0.02
...
0.10
0.02
0.08
0.00
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
1964
36
119
49121
10
0.09
0.45
1.00
0.08
0.11
0.14
...
0.01
1.00
1.00
0.00
1965
18
97
10
1.00
0.36
0.44
0.64
0.06
0.02
...
0.2
1.00
0.17
0.18
0.45
0.19
0.5
0.5
0.44
0.21
1966
6
10
0.09
0.41
0.07
0.74
0.39
0.45
...
0.05
0.29
0.22
0.00
1967
25
17
76135
10
0.01
0.66
0.00
0.97
0.10
0.02
...
0.09
0.04
0.04
0.00
1968
34
25
62430
10
0.00
0.24
0.51
0.53
0.11
0.11
...
0.00
0.50
0.49
0.00
1969
6
10
1.00
0.29
0.21
0.29
1.00
0.26
...
0.16
0.13
1.00
1.00
0.53
0.62
0.64
0.5
0.64
0.35
1970
45
10
0.00
0.37
0.38
0.69
0.04
0.02
...
0.02
0.10
0.08
0.00
1971
1
10
0.06
0.39
0.32
0.73
0.04
0.01
...
0.14
0.09
0.01
0.00
1972
6
10
0.08
0.49
0.07
0.69
0.27
0.35
...
0.07
0.21
0.02
0.00
1973
39
10
0.00
0.38
0.03
0.97
0.04
0.01
...
0.01
0.18
0.10
0.00
1974
37
10
0.00
0.41
0.62
0.51
0.02
0.01
...
0.02
0.10
0.00
0.00
1975
53
10
0.05
0.27
0.03
0.89
0.27
0.04
...
0.03
0.31
0.34
0.00
1976
25
17
1605
10
0.06
0.29
0.03
0.93
0.18
0.03
...
0.01
0.72
0.94
0.00
1977
47
10
0.01
0.35
0.06
0.94
0.06
0.01
...
0.04
0.12
0.01
0.00
1978
9
1
4720
10
0.01
0.54
0.02
0.94
0.13
0.04
...
0.05
0.09
0.14
0.00
1979
34
39
61530
10
0.02
0.43
0.39
0.63
0.15
0.14
...
0.01
0.53
0.43
0.00
1980
25
5
69170
10
0.06
0.43
0.04
0.93
0.03
0.09
...
0.13
0.09
0.11
0.00
1981
9
9
35650
10
0.07
0.38
0.17
0.84
0.11
0.04
...
0.25
0.09
0.13
0.17
0.02
0.01
0.72
0
0.62
0.15
1982
42
133
73168
10
0.00
0.47
0.02
0.98
0.03
0.01
...
0.02
0.14
0.04
0.00
1983
13
10
0.01
0.45
0.37
0.65
0.15
0.05
...
0.02
0.16
0.13
0.00
1984
39
95
48342
10
0.01
0.43
0.01
0.98
0.03
0.02
...
0.02
0.15
0.06
0.00
1985
1
10
0.01
0.41
0.55
0.57
0.01
0.00
...
0.11
0.03
0.01
0.00
1986
9
3
70550
10
0.05
0.52
0.02
0.97
0.04
0.02
...
0.10
0.09
0.03
0.00
1987
44
7
11800
10
0.01
0.65
0.00
1.00
0.01
0.01
...
0.16
0.02
0.02
0.00
1988
28
10
0.02
0.41
1.00
0.21
0.02
0.01
...
0.03
0.17
0.02
0.00
1989
12
10
0.01
0.40
0.10
0.87
0.12
0.16
...
0.01
0.28
0.05
0.00
1990
6
10
0.05
0.96
0.46
0.28
0.83
0.32
...
0.02
0.37
0.20
0.00
1991
9
9
80070
10
0.16
0.37
0.25
0.69
0.04
0.25
...
0.25
0.08
0.32
0.18
0.08
0.06
0.78
0
0.91
0.28
1992
25
17
72600
10
0.08
0.51
0.06
0.87
0.22
0.10
...
0.19
0.03
0.38
0.33
0.02
0.02
0.79
0
0.22
0.18
1993
6
10
0.20
0.78
0.14
0.46
0.24
0.77
...
0.11
0.11
0.30
0.05
0.08
0.04
0.73
0.5
1.00
0.13
1994 rows × 126 columns
In [ ]:
Content source: jarvis-fga/Projetos
Similar notebooks: