日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

spotify音乐下载_使用Python和R对音乐进行聚类以在Spotify上创建播放列表。

發布時間:2023/12/15 python 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spotify音乐下载_使用Python和R对音乐进行聚类以在Spotify上创建播放列表。 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

spotify音樂下載

Spotify is one of the most famous Music Platforms to discover new music. The company uses a lot of different algorithms to recommend the user new music based on their music preferences and most of these recommendations are located in Playlists. These Playlists are created for different users based on a wide diversity of music genres and even Spotify is capable to recommend new music based in moods.

小號 potify是最有名的音樂平臺之一,以發現新的音樂。 該公司使用許多不同的算法根據用戶的音樂喜好向他們推薦新音樂,并且其中大多數推薦都位于播放列表中。 這些播放列表是根據各種各樣的音樂類型為不同的用戶創建的,甚至Spotify也能夠根據心情推薦新音樂。

Music has been in my daily routine during all my life, It’s a kind of drug that I need when I’m doing housework, working at the office, walking the dog, workouts and so on. I have a lot of music on Spotify that I always wanted to separate according to the similarities of the songs and save them into different playlists. Fortunately, with a little knowledge of Machine Learning Algorithms and Python, I could achieve that goal !!!.

在我的一生中,音樂一直是我的日常生活,這是我做家務,在辦公室工作,walking狗,鍛煉身體時需要的一種藥物。 我在Spotify上有很多音樂,我一直想根據歌曲的相似性進行分離,然后將它們保存到不同的播放列表中。 幸運的是,只要對機器學習算法和Python有所了解,我就能實現這一目標!

So to do that, first I will list the tools required and some definitions of the Spotify Audio Features that I will use for built the Clustering model.

為此,首先,我將列出所需的工具以及將用于構建集群模型的Spotify音頻功能的一些定義。

工具: (Tools:)

  • Pandas and Numpy for data analysis.

    Pandas和Numpy用于數據分析。
  • Sklearn to build the Machine Learning model.

    Sklearn建立機器學習模型。
  • Spotipy Python Library (click here for more info).

    Spotipy Python庫( 單擊此處了解更多信息)。

  • Spotify Credentials to access Api Database and Playlists Modify (click here for more info).

    Spotify憑據可訪問Api數據庫和播放列表修改( 單擊此處了解更多信息)。

Spotify音頻功能: (Spotify Audio Features:)

Spotify uses a series of different features to classify the tracks. I copy/paste the information from the Spotify Webpage.

Spotify使用一系列不同的功能對曲目進行分類。 我從Spotify網頁復制/粘貼信息。

  • Acousticness: A confidence measure from 0.0 to 1.0 of whether the track is acoustic. 1.0 represents high confidence the track is acoustic.

    聲學:軌道是否聲學的置信度,范圍為0.0到1.0。 1.0表示音軌是聲學的高置信度。
  • Danceability: Danceability describes how suitable a track is for dancing based on a combination of musical elements including tempo, rhythm stability, beat strength, and overall regularity. A value of 0.0 is least danceable and 1.0 is most danceable.

    舞蹈性:舞蹈性是根據節奏,節奏穩定性,拍子強度和整體規律性等音樂元素的組合來描述軌道適合跳舞的方式。 值0.0最低可跳舞,而1.0最高可跳舞。
  • Energy: Energy is a measure from 0.0 to 1.0 and represents a perceptual measure of intensity and activity. Typically, energetic tracks feel fast, loud, and noisy. For example, death metal has high energy, while a Bach prelude scores low on the scale. Perceptual features contributing to this attribute include dynamic range, perceived loudness, timbre, onset rate, and general entropy.

    能量:能量是從0.0到1.0的量度,表示強度和活動的感知量度。 通常,充滿活力的曲目會感覺快速,響亮且嘈雜。 例如,死亡金屬具有較高的能量,而巴赫前奏的得分則較低。 有助于此屬性的感知特征包括動態范圍,感知的響度,音色,發作率和一般熵。
  • Instrumentalness: Predicts whether a track contains no vocals. “Ooh” and “aah” sounds are treated as instrumental in this context. Rap or spoken word tracks are clearly “vocal”. The closer the instrumentalness value is to 1.0, the greater likelihood the track contains no vocal content. Values above 0.5 are intended to represent instrumental tracks, but confidence is higher as the value approaches 1.0.

    器樂性:預測曲目是否不包含人聲。 在這種情況下,“哦”和“啊”的聲音被當作工具。 說唱或說出的單詞軌跡顯然是“發聲的”。 器樂性值越接近1.0,則軌道中沒有聲音的可能性越大。 高于0.5的值旨在表示樂器軌跡,但隨著該值接近1.0,置信度更高。
  • Liveness: Detects the presence of an audience in the recording. Higher liveness values represent an increased probability that the track was performed live. A value above 0.8 provides a strong likelihood that the track is live.

    生動度:檢測記錄中是否有聽眾。 較高的活躍度值表示增加了實時執行軌道的可能性。 高于0.8的值很有可能會啟用該軌道。
  • Loudness: the overall loudness of a track in decibels (dB). Loudness values are averaged across the entire track and are useful for comparing the relative loudness of tracks. Loudness is the quality of a sound that is the primary psychological correlate of physical strength (amplitude). Values typically range between -60 and 0 db.

    響度:軌道的整體響度,以分貝(dB)為單位。 響度值是整個軌道的平均值,可用于比較軌道的相對響度。 響度是聲音的質量,它是身體力量(振幅)的主要心理關聯。 值通常在-60到0 db之間。
  • Speechiness: Speechiness detects the presence of spoken words in a track. The more exclusively speech-like the recording (e.g. talk show, audiobook, poetry), the closer to 1.0 the attribute value. Values above 0.66 describe tracks that are probably made entirely of spoken words. Values between 0.33 and 0.66 describe tracks that may contain both music and speech, either in sections or layered, including such cases as rap music. Values below 0.33 most likely represent music and other non-speech-like tracks.

    語音能力:語音能力可檢測曲目中是否存在口語。 與錄音類似的錄音(例如脫口秀,有聲讀物,詩歌)越多,屬性值就越接近1.0。 高于0.66的值描述的曲目可能完全由口語組成。 介于0.33到0.66之間的值描述了可能同時包含音樂和語音的曲目,無論是分段還是分層的(包括說唱音樂)。 低于0.33的值最有可能代表音樂和其他非語音類曲目。
  • Valence: A measure from 0.0 to 1.0 describing the musical positiveness conveyed by a track. Tracks with high valence sound more positive (e.g. happy, cheerful, euphoric), while tracks with low valence sound more negative (e.g. sad, depressed, angry).

    價:從0.0到1.0的小節,描述了曲目傳達的音樂積極性。 價態高的音軌聽起來更積極(例如,快樂,開朗,欣快),而價態低的音軌聽起來更加消極(例如,悲傷,沮喪,憤怒)。
  • Tempo: The overall estimated tempo of a track in beats per minute (BPM). In musical terminology, the tempo is the speed or pace of a given piece and derives directly from the average beat duration.

    速度:以每分鐘節拍數(BPM)為單位的曲目的總體估計速度。 用音樂術語來說,節奏是指給定樂曲的速度或節奏,它直接來自平均拍子持續時間。

For information reduction purposes I decided to use the features of Loudness, Valence, Energy, and Danceability because they have more influence to differentiate between Energetic and Relaxed songs.

為了減少信息量,我決定使用響度能量和可跳舞性的功能,因為它們具有更大的影響力來區分活力和輕松的歌曲。

1.獲取和分析數據: (1. Obtaining and Analysing the Data:)

My favorite band is Radiohead, so I decided to obtain their discography and all the music created by the musicians in their solo music careers.

我最喜歡的樂隊是Radiohead ,所以我決定獲得他們的唱片以及音樂家在其個人音樂事業中創作的所有音樂。

Using the Spotipy Library I created some functions to download all the songs of Radiohead, Thom Yorke, Atoms For Peace, Jonny Greenwood, Ed O’Brien, Colin Greenwood, and Phil Selway (Yes, I’m obsessed with their music hehe). You can access those functions on my Github Repository (click here).

使用Spotipy庫,我創建了一些函數來下載RadioheadThom YorkeAtoms For PeaceJonny GreenwoodEd O'BrienColin GreenwoodPhil Selway的所有歌曲(是的,我很著迷于他們的音樂呵呵)。 您可以在我的Github存儲庫中訪問這些功能( 單擊此處 )。

I obtained the following data:

我獲得了以下數據:

Data Frame with shape of 423 rows and 10 columns. (Image by author)具有423行和10列形狀的數據框。 (作者提供的圖片)

I always wondered why I like a lot the music of Radiohead and I realized that most of their songs tend towards melancholy. Describing the features above, the data showed me that Valence and Energy are less than 0.5 and Danceability tends to low values, so I like tracks with low energy and negative sound (there is still something of my 2000’s Emo Side watching MTV Videos).

我一直想知道為什么我非常喜歡Radiohead的音樂,并且我意識到他們的大多數歌曲都傾向于憂郁。 描述上述功能后,數據顯示價價和能量小于0.5,而可跳舞性趨向于低值,因此我喜歡低能量和負面聲音的音軌(仍然有我2000年的Emo Side觀看MTV視頻的內容)。

Main Stats of Data Frame (Image by author)數據框的主要統計數據(作者提供) Histograms of Songs Features (Image by author)歌曲直方圖功能(作者提供)

2.建立模型: (2. Building the Model:)

I decided to use K-means Clustering for Unsupervised Machine Learning due to the shape of my data (423 tracks ) and considering I want to create 2 playlists separating Relaxed tracks from Energetic tracks (K=2).

由于數據的形狀(423個音軌),我決定將K均值聚類用于無監督機器學習,并考慮到我要創建2個播放列表,將輕松音軌與能量音軌(K = 2)分開。

Important: I’m not using train and test data because in this case I just want to group all the tracks into 2 different groups to create playlists with the entire data.

重要提示 :我不使用訓練和測試數據,因為在這種情況下,我只想將所有軌道分為2個不同的組,以創建包含整個數據的播放列表。

So let’s do it!. I first import the libraries:

因此,讓我們開始吧! 我首先導入庫:

from sklearn.cluster import KMeansfrom sklearn.preprocessing import MinMaxScaler

Then I need to define features and normalize the values of the model. I’ will use MinMaxScaler to preserve the shape of the original distribution and scale the features between a range from 0 to 1. Once I have the values in the correct format, I just simply create the K-Means model and then save the labels into the main Data Frame called “df”.

然后,我需要定義特征并標準化模型的值。 我將使用MinMaxScaler保留原始分布的形狀,并在0到1的范圍內縮放要素 。一旦以正確的格式獲得了值,我只需創建K-Means模型,然后將標簽保存到主數據幀稱為“ df”。

col_features = ['danceability', 'energy', 'valence', 'loudness']
X = MinMaxScaler().fit_transform(df[col_features])kmeans = KMeans(init="kmeans++",
n_clusters=2,
random_state=15).fit(X)df['kmeans'] = kmeans.labels_

That’s All, I have the music clustered in 2 groups !!!

就是這樣,我將音樂分為2組!!!

But now I need to study the features of these labels, so I plot the tracks in a 3D Scatter and then I analyze the respective mean of each feature grouping the data frame by the K-Means result labels.

但是現在我需要研究這些標簽的特征,因此我將軌跡繪制在3D散點圖中,然后分析通過K-Means結果標簽將數據框分組的每個特征的平均值。

3D Scatter plot of tracks using the features “Energy”, “Danceability” and “Loudness” (Image by author)使用“能量”,“可跳舞性”和“響度”功能的3D散點圖(作者提供) Mean Features of each K-mean Label (Image by author)每個K均值標簽的平均特征(作者提供的圖片)

As I noticed on the graph the values are quite well grouped, blue values are located in label 0 and red values in label 1. Looking at the table of means, the label 0 grouped tracks with less danceability, energy, valence, loudness, so this one corresponds to Relaxed songs, likewise, the label 1 has the Energetic songs.

正如我在圖表上所注意到的,這些值被很好地分組了,藍色值位于標簽0中,紅色值位于標簽1中。從均值表來看, 標簽0分組后的音軌具有較低的可跳舞性,活力,化合價,響度,因此這首歌曲對應于“輕松的歌曲” ,同樣, 標簽1具有“勁歌” 。

3.具有R的模型的準確性: (3. Accuracy of the Model with R:)

I know that Clustering accuracy is a bit subjective trying to evaluate the best result of a Clustering Algorithm, but in the same way, I wanted to observe if my model is separating the tracks well. So with a little help from Rstudio, I used the Silhouette Analysis. to measure the accuracy of my model.

我知道聚類精度在嘗試評估聚類算法的最佳結果時有點主觀,但是以同樣的方式,我想觀察我的模型是否很好地分隔了軌道。 因此,在Rstudio的一點幫助下,我使用了“輪廓分析”。 來衡量我模型的準確性。

In Rstudio I used the library “cluster” and “factoextra” to visualize and calculate the Silhouette Analysis using the Euclidean distance. the complete code is on my Github Repository (click here):

在Rstudio中,我使用庫“群集”和“ factoextra”來使用歐幾里得距離可視化和計算“輪廓分析”。 完整的代碼在我的Github存儲庫中( 單擊此處 ):

#Calculate The euclidean distance of my dataframe values.
dd <- dist(df,method="euclidean")#Silhouette Analysis using the K-means model(km) and distance(dd)
sil.km <- silhouette(km$cluster,dd)
fviz_silhouette(sil.km)

The result is:

結果是:

Silhouette Analysis (Image by author)輪廓分析(作者提供)

The Silhouette Analysis is a way to measure how close each point in a cluster is to the points in its neighboring clusters. Silhouette values lies in the range of [-1, 1]. A value of +1 indicates that the sample is far away from its neighboring cluster and very close to the cluster its assigned. Similarly, a value of -1 indicates that the point is close to its neighboring cluster than to the cluster its assigned. So in my case values are between 0.25 and 0.60 inferring that most of the values are quite well grouped.

輪廓分析是一種測量聚類中的每個點與其相鄰聚類中的點的接近程度的方法。 輪廓值在[-1,1]的范圍內。 值+1表示樣本離其鄰近的簇很遠,并且非常接近為其分配的簇。 類似地,值-1表示該點比其分配的群集更靠近其相鄰群集。 因此,在我的情況下,值介于0.25和0.60之間,這表明大多數值都進行了很好的分組。

4.在Spotify上創建播放列表: (4. Creating the Playlists on Spotify:)

To create the playlists and add the clustered tracks I use the library Spotipy explained in the first part of this article. You just need to get a client id, client secret, and username code to use the Spotify’s Apis and manipulate your library music. I let you the link with the information (Click Here).

為了創建播放列表并添加群集的曲目,我使用了本文第一部分中解釋的庫Spotipy。 您只需要獲取客戶端ID,客戶端密鑰和用戶名代碼,即可使用Spotify的Apis并操作您的音樂庫。 我讓您鏈接信息( 單擊此處 )。

I had to separate the tracks grouped into 2 different variables and then having the ids of the tracks I just create 2 new playlists and pass them the ids of the tracks. The code is the following one:

我必須將軌道分為2個不同的變量,然后讓它們的ID分別創建兩個新的播放列表,并將它們的ID傳遞給它們。 代碼如下:

#Separating the clusters into new variables
cluster_0 = df[df['kmeans']==0]
cluster_1 = df[df['kmeans']==1]#Obtaining the ids of the songs and conver the id dataframe column to a list.
ids_0 = cluster_0['id'].tolist()
ids_1 = cluster_1['id'].tolist()#Creating 2 new playlists on my Spotify User
pl_energy = sp.user_playlist_create(username=username,
name="Radiohead :)")pl_relaxed = sp.user_playlist_create(user=username,
name="Radiohead :(")#Adding the tracks into the playlists
#For energetic Playlist
sp.user_playlist_add_tracks(user=username,
playlist_id = pl_energy['id'],
tracks=ids_1)#For relaxed Playlist
sp.user_playlist_add_tracks(user=username,
playlist_id = pl_relaxed['id'],
tracks=ids_0)

Finally, I have my 2 playlists of Radiohead’s songs using a K-means Clustering Algorithm to separate Energetic Songs from Relaxed Songs !!!!.

最后,我有2個Radiohead歌曲的播放列表,使用K-means聚類算法將精力充沛的歌曲與輕松的歌曲分開!!!!

If you want to listen to both playlists you can access them below.

如果您想同時收聽兩個播放列表,則可以在下面訪問它們。

最具活力的Radiohead歌曲(209首曲目) (Most Energetic Radiohead Songs (209 tracks))

Playlist created by the author作者創建的播放列表

最輕松的Radiohead歌曲(214首曲目) (Most Relaxed Radiohead Songs (214 tracks))

Playlist created by the author作者創建的播放列表

結論 (Conclusion)

Machine Learning Algorithms are a lot of fun to implement ideas or projects related to things you like. In my case, I like music a lot, so I could use this knowledge to create cool ways helping me to automate a task that can take a long time to perform it. I also could learn more about this amazing world of Data Science and my tendencies to music tastes.

機器學習算法對于實現與您喜歡的事物相關的想法或項目很有趣。 就我而言,我非常喜歡音樂,因此我可以利用這些知識來創建一些很酷的方法,以幫助我自動執行一項需要很長時間才能完成的任務。 我還可以了解有關數據科學這個神奇世界的更多信息,以及我對音樂品味的傾向。

翻譯自: https://towardsdatascience.com/clustering-music-to-create-your-personal-playlists-on-spotify-using-python-and-k-means-a39c4158589a

spotify音樂下載

總結

以上是生活随笔為你收集整理的spotify音乐下载_使用Python和R对音乐进行聚类以在Spotify上创建播放列表。的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产精品一区视频 | 久一区二区三区 | 插久久 | 亚州一区二区 | 日韩精品中文在线 | 国产a级大片 | 美女喷液视频 | 大白屁股一区二区视频 | 超碰在线观看免费 | 午夜av网站 | 爱久久 | 午夜精品一区二区三区三上悠亚 | 免费网站黄色 | 一进一出好爽视频 | 草色噜噜噜av在线观看香蕉 | 看日本黄色录像 | 色就操| 男男黄色片 | 淫综合网 | 在线观看免费视频一区 | 免费在线日韩av | 99re视频精品| 亚洲精品97| 日本不卡一区二区三区视频 | 69视频在线免费观看 | 色国产精品 | www香蕉| 在线观看国产视频 | www色日本| 日韩免费成人av | 粉嫩小泬无遮挡久久久久久 | 欧美日韩人妻精品一区二区 | 国产精品xxx在线 | 久久九精品| 色黄网站在线观看 | 最新99热 | 国产第一页第二页 | 色狠狠综合网 | 中国美女一级看片 | 自拍偷拍第3页 | 亚洲九九热 | 九九久久国产视频 | 天天网综合 | 免费色网站 | 深夜福利视频在线 | 国产精品香蕉 | 国产成人精品亚洲线观看 | 日日干日日草 | 亚洲综合自拍 | 日韩国产成人 | 午夜在线免费观看 | 日本精品视频一区 | 中文字幕国产一区 | 高潮一区二区三区 | 99免费在线观看 | 精品久久久久久无码国产 | 国产欧美久久久精品免费 | h视频免费在线观看 | 给我看高清的视频在线观看 | 欧美一级片播放 | 91传媒网站 | 97操| 在线视频日韩欧美 | 亚洲第一二区 | a级片在线免费看 | 麻豆传媒一区二区三区 | 国产精品视频一区二区三区在3 | 免费看黄色片的网站 | 美女一区二区三区 | 伦一理一级一a一片 | avtt在线| 国产成人二区 | 日日碰| 欧美日韩精品一区二区三区蜜桃 | 4444亚洲人成无码网在线观看 | 精品无码在线观看 | 日韩 欧美 精品 | 国产精品国产三级国产播12软件 | 暖暖免费观看日本版 | 亚洲一区自拍 | 国产精品日韩一区 | 波多野结衣中文字幕一区二区 | 国产做爰免费观看视频 | 天堂中文网 | 无码精品人妻一区二区 | 国产精品hd | 亚洲AV成人无码网站天堂久久 | 亚洲av无码国产精品永久一区 | 美女主播在线观看 | 成人福利视频网 | 亚洲欧美日韩国产 | 国内成人精品视频 | 在线视频1卡二卡三卡 | 国产性自拍 | 91精品国产麻豆国产自产在线 | 一级特黄aaa大片 | 国产探花精品一区二区 | 天天操天天曰 | 国产第六页 |