-
Notifications
You must be signed in to change notification settings - Fork 0
/
music.Rmd
106 lines (88 loc) · 2.87 KB
/
music.Rmd
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
---
title: "Music"
output:
html_document:
df_print: paged
---
```{r}
library(DBI)
library(RSQLite)
library(dplyr)
#make sure you get the sqlite file here
con <- dbConnect(SQLite(), "Attachment_1645043751.sqlite")
# Show List of Tables
as.data.frame(dbListTables(con))
```
```{r}
# Get table
album<- dbReadTable(con, 'Album')
artist<- dbReadTable(con, 'Artist')
tracks<- dbReadTable(con, 'Track')
genre<- dbReadTable(con, 'Genre')
# data is fetched so disconnect it.
dbDisconnect(con)
```
#1
```{r}
left_join(tracks, album,
by = c("AlbumId" = "AlbumId")) %>% group_by(ArtistId) %>% count(ArtistId) %>% arrange(desc(n))
```
#2
```{r}
left_join(genre, tracks,
by = c("GenreId" = "GenreId")) %>% count(Name.x)
```
#3
```{r}
# Fit the model
model <- glm( diabetes ~., data = train.data, family = binomial)
# Summarize the model
summary(model)
# Make predictions
probabilities <- model %>% predict(test.data, type = "response")
predicted.classes <- ifelse(probabilities > 0.5, "pos", "neg")
# Model accuracy
mean(predicted.classes == test.data$diabetes)
Simple logistic regression
```
#4
```{r}
yelp <- "https://api.yelp.com"
term <- "Where is the best italian food in kalamazoo,MI?"
location <- "Kalamazoo"
categories <- NULL
limit <- 50
radius <- 8800
url <- modify_url(yelp, path = c("v3", "businesses", "search"),
query = list(term = term, location = location,
limit = limit,
radius = radius))
res <- GET(url, add_headers('Authorization' = paste("bearer", client_secret)))
results <- content(res)
yelp_httr_parse <- function(x) {
parse_list <- list(id = x$id,
name = x$name,
rating = x$rating,
review_count = x$review_count,
latitude = x$coordinates$latitude,
longitude = x$coordinates$longitude,
address1 = x$location$address1,
city = x$location$city,
state = x$location$state,
distance = x$distance)
parse_list <- lapply(parse_list, FUN = function(x) ifelse(is.null(x), "", x))
df <- data_frame(id=parse_list$id,
name=parse_list$name,
rating = parse_list$rating,
review_count = parse_list$review_count,
latitude=parse_list$latitude,
longitude = parse_list$longitude,
address1 = parse_list$address1,
city = parse_list$city,
state = parse_list$state,
distance= parse_list$distance)
df
}
results_list <- lapply(results$businesses, FUN = yelp_httr_parse)
business_data <- do.call("rbind", results_list)
```