-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewyork.jl
170 lines (140 loc) · 4.5 KB
/
newyork.jl
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using MLJFlux, Flux, MLJ, DataFrames, CSV, StatsBase
origindata = CSV.read("data/newyork-city-airbnb-open-data/AB_NYC_2019.csv", DataFrame)
featureSelector = FeatureSelector(
features = [:id, :name, :host_name, :last_review],
ignore = true
)
dropMissing(dataframe::DataFrame) = begin
dropmissing(dataframe, :reviews_per_month)
end
processLongitude(dataframe::DataFrame) = begin
dataframe[!, :longitude] = map(floor, dataframe[!, :longitude])
array = unique(dataframe[!, :longitude])
dict = Dict{Float64, Float64}()
for (index, value) in Iterators.enumerate(array)
dict[value] = index
end
dataframe[!, :longitude] = map(x -> dict[x], dataframe[!, :longitude])
return dataframe
end
processNeighbourhoodGroup(dataframe::DataFrame) = begin
array = unique(dataframe[!, :neighbourhood_group])
dict = Dict{String, Int}()
for (index, value) in Iterators.enumerate(array)
dict[value] = index
end
dataframe[!, :neighbourhood_group] = map(x -> dict[x], dataframe[!, :neighbourhood_group])
return dataframe
end
processNeighbourhood(dataframe::DataFrame) = begin
array = unique(dataframe[!, :neighbourhood])
dict = Dict{String, Int}()
for (index, value) in Iterators.enumerate(array)
dict[value] = index
end
dataframe[!, :neighbourhood] = map(x -> dict[x], dataframe[!, :neighbourhood])
return dataframe
end
processRoomType(dataframe::DataFrame) = begin
array = unique(dataframe[!, :room_type])
dict = Dict{String, Int}()
for (index, value) in Iterators.enumerate(array)
dict[value] = index
end
dataframe[!, :room_type] = map(x -> dict[x], dataframe[!, :room_type])
return dataframe
end
coerceCount(dataframe::DataFrame) = begin
coerce(dataframe, Count => Continuous)
end
# DONE transform data
transformModel = Pipeline(
featureSelector,
dropMissing,
processLongitude,
processNeighbourhoodGroup,
processNeighbourhood,
processRoomType,
coerceCount
)
transformMachine = machine(transformModel, origindata)
fit!(transformMachine)
transformedData = MLJ.transform(transformMachine, origindata)
using Plots, StatsPlots
plotly()
figuresize = (1200, 900)
# DONE plotting all neighbourhood group
let
counts = countmap(origindata[!, :neighbourhood_group])
bar(collect(keys(counts)), collect(values(counts)),
title = "Neighbourhood Group",
size = figuresize) |> display
end
# DONE plotting neighbourhood
let
counts = countmap(origindata[!, :neighbourhood])
bar(collect(keys(counts)), collect(values(counts)),
xrotation = -90,
xticks = :all,
size = figuresize,
title = "Neighbourhood") |> display
end
# DONE plotting room type
let
counts = countmap(origindata[!, :room_type])
bar(collect(keys(counts)), collect(values(counts)), size = figuresize) |> display
end
# DONE plotting relation between neighbourhood_group and availability_365 of room
let
x = origindata[!, :neighbourhood_group]
y = origindata[!, :availability_365]
boxplot(x, y, size = figuresize) |> display
end
# DONE plotting map of neighbourhood_group
let
array = unique(origindata[!, :neighbourhood_group])
colors = [:red, :green, :blue, :black, :yellow]
dict = Dict{String, Symbol}()
for (index, value) in Iterators.enumerate(array)
dict[value] = colors[index]
end
markercolors = map(x -> dict[x], origindata[!, :neighbourhood_group])
scatter(origindata[!, :longitude], origindata[!, :latitude],
markercolor = markercolors,
size = figuresize) |> display
end
# DOING plotting map of neighbourhood
let
array = unique(origindata[!, :room_type])
colors = [:red, :green, :blue]
dict = Dict{String, Symbol}()
for (index, value) in Iterators.enumerate(array)
dict[value] = colors[index]
end
markercolors = map(x -> dict[x], origindata[!, :room_type])
scatter(origindata[!, :longitude], origindata[!, :latitude],
markercolor = markercolors,
size = figuresize) |> display
end
# DONE availability of room
let
mapcolor(number::Number) = begin
if number >= 0 && number < 150
return :red
elseif number >= 150 && number < 300
return :green
elseif number >= 300 && number < 450
return :blue
else
return :black
end
end
markercolors = map(mapcolor, origindata[!, :availability_365])
scatter(origindata[!, :longitude], origindata[!, :latitude],
markercolor = markercolors,
size = figuresize) |> display
end
# TODO word cloud
using WordCloud
wc = wordcloud(origindata[!, :neighbourhood]) |> generate!
paint(wc, "/home/steiner/Downloads/neighbourhood.png")