Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Lista 2

INF222/lista_dois/respostas.livemd

Lista 2

Mix.install([
  {:kino, "~> 0.6.2"},
  {:kino_vega_lite, "~> 0.1.3"},
  {:explorer, "~> 0.3.1"}
])
:ok

Questão 1

Os gráficos abaixo corroboram as afirmações feitas no Exercício 1.

atores = [
  %{bin_start: 20, bin_end: 30, count: 1},
  %{bin_start: 30, bin_end: 40, count: 25},
  %{bin_start: 40, bin_end: 50, count: 30},
  %{bin_start: 50, bin_end: 60, count: 14},
  %{bin_start: 60, bin_end: 70, count: 3},
  %{bin_start: 70, bin_end: 80, count: 1},
  %{bin_start: 80, bin_end: 90, count: 0}
]

VegaLite.new(width: 400, height: 400, title: "Histograma de Atores")
|> VegaLite.data_from_values(atores)
|> VegaLite.mark(:bar)
|> VegaLite.encode_field(:x, "bin_start", bin: %{binned: true, step: 10}, title: "Atores")
|> VegaLite.encode_field(:x2, "bin_end")
|> VegaLite.encode_field(:y, "count", type: :quantitative, title: "Quantidade")
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"values":[{"bin_end":30,"bin_start":20,"count":1},{"bin_end":40,"bin_start":30,"count":25},{"bin_end":50,"bin_start":40,"count":30},{"bin_end":60,"bin_start":50,"count":14},{"bin_end":70,"bin_start":60,"count":3},{"bin_end":80,"bin_start":70,"count":1},{"bin_end":90,"bin_start":80,"count":0}]},"encoding":{"x":{"bin":{"binned":true,"step":10},"field":"bin_start","title":"Atores"},"x2":{"field":"bin_end"},"y":{"field":"count","title":"Quantidade","type":"quantitative"}},"height":400,"mark":"bar","title":"Histograma de Atores","width":400}
atrizes = [
  %{bin_start: 20, bin_end: 30, count: 28},
  %{bin_start: 30, bin_end: 40, count: 30},
  %{bin_start: 40, bin_end: 50, count: 12},
  %{bin_start: 50, bin_end: 60, count: 2},
  %{bin_start: 60, bin_end: 70, count: 2},
  %{bin_start: 70, bin_end: 80, count: 1},
  %{bin_start: 80, bin_end: 90, count: 1}
]

VegaLite.new(width: 400, height: 400, title: "Histograma de Atrizes")
|> VegaLite.data_from_values(atrizes)
|> VegaLite.mark(:bar)
|> VegaLite.encode_field(:x, "bin_start", bin: %{binned: true, step: 10}, title: "Atrizes")
|> VegaLite.encode_field(:x2, "bin_end")
|> VegaLite.encode_field(:y, "count", type: :quantitative, title: "Quantidade")
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"values":[{"bin_end":30,"bin_start":20,"count":28},{"bin_end":40,"bin_start":30,"count":30},{"bin_end":50,"bin_start":40,"count":12},{"bin_end":60,"bin_start":50,"count":2},{"bin_end":70,"bin_start":60,"count":2},{"bin_end":80,"bin_start":70,"count":1},{"bin_end":90,"bin_start":80,"count":1}]},"encoding":{"x":{"bin":{"binned":true,"step":10},"field":"bin_start","title":"Atrizes"},"x2":{"field":"bin_end"},"y":{"field":"count","title":"Quantidade","type":"quantitative"}},"height":400,"mark":"bar","title":"Histograma de Atrizes","width":400}

Questão 2

Levando em consideração a hipótese “pessas acima de 70 anos não possuem uma quantidade extremamente reduzida de prêmios”. Podemos usar o seguinte gráfico para a prova.

academy_awards = [
  %{category: "<= 70", value: 147},
  %{category: "> 70", value: 5}
]

VegaLite.new(width: 400, height: 400)
|> VegaLite.data_from_values(academy_awards)
|> VegaLite.mark(:arc)
|> VegaLite.encode_field(:theta, "value", type: :quantitative)
|> VegaLite.encode_field(:color, "category", type: :nominal)
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"values":[{"category":"<= 70","value":147},{"category":"> 70","value":5}]},"encoding":{"color":{"field":"category","type":"nominal"},"theta":{"field":"value","type":"quantitative"}},"height":400,"mark":"arc","width":400}

Questão 3

store_data = Explorer.DataFrame.from_csv!("store.csv")
Explorer.DataFrame.mutate_with(store_data, &amp;[Renda: Explorer.Series.cast(&amp;1["Renda"], :float)])
gender = Explorer.Series.count(store_data["Sexo"]) |> Explorer.DataFrame.to_columns()

VegaLite.new(width: 400, height: 400, title: "Sexo dos Clientes")
|> VegaLite.data_from_values(gender)
|> VegaLite.mark(:arc)
|> VegaLite.encode_field(:theta, "counts", type: :quantitative)
|> VegaLite.encode_field(:color, "values", type: :nominal)
warning: variable "store_data" does not exist and is being expanded to "store_data()", please use parentheses to remove the ambiguity or change the variable name
  /home/lucasjoviniano/dev/UFV/INF222/lista_dois/respostas.livemd#cell:1
Explorer.Series.count(store_data["Sexo"])
warning: variable "store_data" does not exist and is being expanded to "store_data()", please use parentheses to remove the ambiguity or change the variable name
  /home/lucasjoviniano/dev/UFV/INF222/lista_dois/respostas.livemd#cell:1
age = %{ages: Explorer.DataFrame.pull(store_data, "Idade") |> Explorer.Series.to_list()}
warning: variable "store_data" does not exist and is being expanded to "store_data()", please use parentheses to remove the ambiguity or change the variable name
  /home/lucasjoviniano/dev/UFV/INF222/lista_dois/respostas.livemd#cell:1
VegaLite.new(width: 400, height: 400, title: "Histograma de Idades")
|> VegaLite.data_from_values(age)
|> VegaLite.mark(:bar)
|> VegaLite.encode_field(:x, "ages", bin: true, title: "Idades")
|> VegaLite.encode(:y, aggregate: :count, type: :quantitative, title: "Quantidade")
warning: variable "age" does not exist and is being expanded to "age()", please use parentheses to remove the ambiguity or change the variable name
  /home/lucasjoviniano/dev/UFV/INF222/lista_dois/respostas.livemd#cell:2
income =
  Explorer.DataFrame.pull(store_data, "Renda")
  |> Explorer.Series.count()
  |> Explorer.DataFrame.to_columns()

inc = for _x <- 0..length(income["counts"]), do: :rand.uniform()
income = Map.put(income, "counts", inc)
income
warning: variable "store_data" does not exist and is being expanded to "store_data()", please use parentheses to remove the ambiguity or change the variable name
  /home/lucasjoviniano/dev/UFV/INF222/lista_dois/respostas.livemd#cell:2
VegaLite.new(width: 600, height: 600, title: "Renda")
|> VegaLite.data_from_values(income)
|> VegaLite.mark(:point)
|> VegaLite.encode_field(:x, "counts", type: :quantitative)
|> VegaLite.encode_field(:y, "values", type: :quantitative, title: "Renda")
warning: variable "income" does not exist and is being expanded to "income()", please use parentheses to remove the ambiguity or change the variable name
  /home/lucasjoviniano/dev/UFV/INF222/lista_dois/respostas.livemd#cell:2
cards_per_gender =
  store_data
  |> Explorer.DataFrame.group_by("Sexo")
  |> Explorer.DataFrame.summarise(Cartões: [:sum])
  |> Explorer.DataFrame.to_columns()
warning: variable "store_data" does not exist and is being expanded to "store_data()", please use parentheses to remove the ambiguity or change the variable name
  /home/lucasjoviniano/dev/UFV/INF222/lista_dois/respostas.livemd#cell:2
VegaLite.new(width: 500, height: 500)
|> VegaLite.data_from_values(cards_per_gender)
|> VegaLite.layers([
  VegaLite.new()
  |> VegaLite.mark(:text, radius: 180, font_size: 16)
  |> VegaLite.encode_field(:text, "Cartões_sum", type: :quantitative),
  VegaLite.new()
  |> VegaLite.mark(:arc, radius: 160)
])
|> VegaLite.encode_field(:theta, "Cartões_sum", type: :quantitative, stack: true)
|> VegaLite.encode_field(:color, "Sexo", type: :nominal, title: "Cartões por Sexo")
warning: variable "cards_per_gender" does not exist and is being expanded to "cards_per_gender()", please use parentheses to remove the ambiguity or change the variable name
  /home/lucasjoviniano/dev/UFV/INF222/lista_dois/respostas.livemd#cell:2