{"metadata":{"_change_revision":0,"_is_fork":false,"kernelspec":{"display_name":"R","language":"R","name":"ir"},"language_info":{"name":"R","codemirror_mode":"r","pygments_lexer":"r","mimetype":"text/x-r-source","file_extension":".r","version":"4.0.5"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"Essential to always understand the nature of data. Goal of this R workbook is to share what I learnt as I \nstart to look into dataset without doing any tangible data processing. I've released also the ggplot code\nwhich I found very useful is understanding, and conveying the message.","metadata":{"_cell_guid":"94e71fe2-5fdd-afbd-bffa-d3b332c87722"}},{"cell_type":"code","source":"# This R environment comes with all of CRAN preinstalled, as well as many other helpful packages\n# The environment is defined by the kaggle/rstats docker image: https://github.com/kaggle/docker-rstats\n# For example, here's several helpful packages to load in \n\nlibrary(ggplot2) # Data visualization\nlibrary(readr) # CSV file I/O, e.g. the read_csv function\nlibrary(dplyr)\nlibrary(tidyr)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nsystem(\"ls ../input\")\n\n# Any results you write to the current directory are saved as output.","metadata":{"_cell_guid":"e95dadbd-b60a-6815-e548-a7889fae10ea"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"artists <- read.csv(\"../input/train_info.csv\")\nstr(artists)","metadata":{"_cell_guid":"0d4c9889-4f7f-fb40-9b0f-0385f1e8e5df"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Lets see how many artists are in the training ","metadata":{"_cell_guid":"0cec8286-0713-981f-bde9-0e88865b4cbe"}},{"cell_type":"code","source":"Lets see how many artists works are in the training","metadata":{"_cell_guid":"ac0f0940-19fd-0027-4464-7bdf2bcf3f5e"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"artists  %>% group_by(artist,genre) %>%  summarise(total = n()) %>%  arrange(desc(total,artist)) %>% ggplot(aes(reorder(artist,total),total)) + \ngeom_bar(stat=\"identity\",width = 0.7) + theme(axis.text.x = element_text(angle = 90)) + ylab(\"Number of works\") + \nxlab(\"Artist\") +\nggtitle(\"No of works by Artist\") +  coord_flip() ","metadata":{"_cell_guid":"9d1cb194-a0e2-45f2-107d-455eedd23b31"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Above plot basically tells that same artist has dabbled in many of the genres and his signature\nis kind of all over the place or is spread. A way to think would be that original dna can be traced, \nquestion is how ?","metadata":{"_cell_guid":"0c97d5ca-c2a4-3623-8a97-19bb3e13f1dc"}},{"cell_type":"markdown","source":"So, have to melt it","metadata":{"_cell_guid":"fdb77a11-47e8-3cdc-083d-e1051eeb2766"}},{"cell_type":"code","source":"library(reshape2)","metadata":{"_cell_guid":"35788e08-179f-075b-6c88-64e6a124ad75"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"artistsbyGenre <- artists  %>% group_by(artist,genre) %>%  \nsummarise(total = n()) %>%  arrange(desc(total,artist)) %>% as.data.frame()","metadata":{"_cell_guid":"4320a1c2-c9f7-24cb-b257-6ce6962a9916"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"artistsbyGenreMelt<- melt(artistsbyGenre, id.vars = c(\"artist\"))\nartistsbyGenreMelt<- melt(artistsbyGenre)\n\n#plot\nartistsbyGenreMelt %>% arrange(desc(value)) %>% \nsample_frac(.20) %>% ggplot(aes(reorder(artist,value), value, fill=genre)) + \ngeom_bar(stat=\"identity\",width = 0.7) + theme(axis.text.x = element_text(angle = 90)) + ylab(\"Value\") + \nxlab(\"Artist\") +\nggtitle(\"Spread by genre\") ","metadata":{"_cell_guid":"ae52fbfa-d8b9-2221-0151-9619839439cd"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Maybe one opyion to try is to group by works of an artist, so read all the works by an artist, \nand create a feaure vector\n\nLets see which artist is more versatile","metadata":{"_cell_guid":"b076d77d-df20-772d-b5b0-9950022ee74a"}},{"cell_type":"code","source":"artistsbyGenre  %>% \ngroup_by(artist) %>%  summarise(total = n())  %>%  arrange(desc(total))  %>% head ","metadata":{"_cell_guid":"a286ff5d-3ec9-5806-d186-8af7d3cbfe55"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"artistsbyGenre  %>% group_by(artist) %>% arrange(artist)  %>%  \nfilter(artist  %in% c('40f86d376acde0d9862ce7493745bdae') ) %>% as.data.frame() %>% nrow()","metadata":{"_cell_guid":"399ee5c8-ba18-736f-7e51-964cef053528"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"So, there exists a disparity i.e whether by the artist who is te most versaile is not the \none who has large corpus? Make sense ? \n\nIf we need to know the volume","metadata":{"_cell_guid":"3b4e56f7-fb67-b5e8-471c-3c857ebae1c7"}},{"cell_type":"code","source":"artistsbyGenre  %>% group_by(artist) %>% arrange(artist) %>%  \nsummarise(totalworks = sum(total)) %>% arrange(desc(totalworks))  %>% as.data.frame()   %>% nrow()","metadata":{"_cell_guid":"6241eacd-6652-589d-c59a-16555de3e88d"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"So, there are 1584 artists, not that many\nLets see, how many works by genre","metadata":{"_cell_guid":"c7e49ccf-6e41-b7ec-f736-4f6376b40815"}},{"cell_type":"code","source":"artistsbyGenre  %>% group_by(genre) %>% arrange(genre) %>%  \nsummarise(totalbygenre = sum(total)) %>% arrange(desc(totalbygenre))  %>% as.data.frame() ","metadata":{"_cell_guid":"9d7bf7fd-9df7-3545-b6a2-ff5c6d27c4e2"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"So, what we need is the traits of an artist \nSo, how about this, so for each artist we create a blueprint\nBlueprint will be composed of all his genres ","metadata":{"_cell_guid":"5f15b6f3-5886-43a5-89bc-32c39ceea12e"}},{"cell_type":"markdown","source":"Total by genre in a plot, portarit , landscape and genre painting are the most\ninfamous or popular in the training ","metadata":{"_cell_guid":"197d3d59-36da-4184-3df4-5ef89d3c9fce"}},{"cell_type":"code","source":"artistsbyGenre  %>% group_by(genre) %>% \narrange(genre) %>%  summarise(totalbygenre = sum(total)) %>% arrange(desc(totalbygenre))  %>% \nas.data.frame() %>% \nggplot(aes(genre,totalbygenre)) +  geom_bar(stat = \"identity\") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) ","metadata":{"_cell_guid":"37510027-397a-d4c5-5a2b-273b71660380"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Lets see the spread by style in a genre, \nthis gives the genre, and the spread of styles within it, and the count","metadata":{"_cell_guid":"3016940e-959f-b10d-2b6f-cae4cf3f2264"}},{"cell_type":"code","source":"artistsByGenreStyle <- artists  %>% group_by(genre,style) %>% arrange(genre) %>%  summarise(totalbygenre = n()) %>% as.data.frame()\n\nartists  %>% group_by(genre,style) %>% \narrange(genre) %>%  summarise(totalbygenre = n()) %>% \nfilter(totalbygenre > 100)%>% as.data.frame() %>% \nggplot( aes(style, totalbygenre, width=.85)) +   \n  geom_bar(aes(fill = genre), position = \"dodge\", stat=\"identity\") +  theme(axis.text.x = element_text(angle = 90, hjust = 1)) + coord_flip()","metadata":{"_cell_guid":"a820ed37-42c3-1d6c-6cb0-ec913e09eaaf","execution":{"iopub.status.busy":"2023-03-20T12:11:55.260186Z","iopub.execute_input":"2023-03-20T12:11:55.263169Z","iopub.status.idle":"2023-03-20T12:11:55.400461Z"},"trusted":true},"execution_count":1,"outputs":[{"ename":"ERROR","evalue":"Error in artists %>% group_by(genre, style) %>% arrange(genre) %>% summarise(totalbygenre = n()) %>% : could not find function \"%>%\"\n","traceback":["Error in artists %>% group_by(genre, style) %>% arrange(genre) %>% summarise(totalbygenre = n()) %>% : could not find function \"%>%\"\nTraceback:\n"],"output_type":"error"}]},{"cell_type":"markdown","source":"So, turn our focus to find the impressionist painters ? Maybe, you will top the leaderboard","metadata":{"_cell_guid":"457fa5c3-fbac-2d62-5f24-2df155f775cf"}},{"cell_type":"code","source":"date","metadata":{"_cell_guid":"aee6e7bb-4dc2-2dc0-9f23-eb67b601e92c"},"execution_count":null,"outputs":[]}]}