Update README.md
Browse files
README.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
This model is extremely weak. I am not good at data science
|
| 2 |
-
|
| 3 |
---
|
| 4 |
license: other
|
| 5 |
license_name: joke
|
|
@@ -9,4 +7,84 @@ datasets:
|
|
| 9 |
pipeline_tag: audio-classification
|
| 10 |
tags:
|
| 11 |
- music
|
| 12 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: other
|
| 3 |
license_name: joke
|
|
|
|
| 7 |
pipeline_tag: audio-classification
|
| 8 |
tags:
|
| 9 |
- music
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
This model is extremely weak. I am not good at data science
|
| 13 |
+
|
| 14 |
+
# Iterations
|
| 15 |
+
**null**:
|
| 16 |
+
|
| 17 |
+
<details>
|
| 18 |
+
<summary><b>Trained on 500 Epoch with 2.1 million song data from Spotify Database</b></summary>
|
| 19 |
+
```python
|
| 20 |
+
import torch
|
| 21 |
+
import torch.nn as nn
|
| 22 |
+
import torch.optim as optim
|
| 23 |
+
from sklearn.model_selection import train_test_split
|
| 24 |
+
from sklearn.preprocessing import StandardScaler
|
| 25 |
+
import pandas as pd
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# Split the data into features and target variable
|
| 29 |
+
X = df[numerical_features[:-1]].values # all except popularity
|
| 30 |
+
y = df['popularity'].values
|
| 31 |
+
|
| 32 |
+
# Split into training and testing sets
|
| 33 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 34 |
+
|
| 35 |
+
# Standardize the features
|
| 36 |
+
scaler = StandardScaler()
|
| 37 |
+
X_train = scaler.fit_transform(X_train)
|
| 38 |
+
X_test = scaler.transform(X_test)
|
| 39 |
+
|
| 40 |
+
# Convert to PyTorch tensors
|
| 41 |
+
X_train_tensor = torch.FloatTensor(X_train)
|
| 42 |
+
y_train_tensor = torch.FloatTensor(y_train).view(-1, 1) # shape to (N, 1)
|
| 43 |
+
X_test_tensor = torch.FloatTensor(X_test)
|
| 44 |
+
y_test_tensor = torch.FloatTensor(y_test).view(-1, 1)
|
| 45 |
+
|
| 46 |
+
# Define the neural network model
|
| 47 |
+
class PopularityPredictor(nn.Module):
|
| 48 |
+
def __init__(self):
|
| 49 |
+
super(PopularityPredictor, self).__init__()
|
| 50 |
+
self.fc1 = nn.Linear(X_train.shape[1], 128)
|
| 51 |
+
self.fc2 = nn.Linear(128, 64)
|
| 52 |
+
self.fc3 = nn.Linear(64, 32)
|
| 53 |
+
self.fc4 = nn.Linear(32, 1)
|
| 54 |
+
|
| 55 |
+
def forward(self, x):
|
| 56 |
+
x = torch.relu(self.fc1(x))
|
| 57 |
+
x = torch.relu(self.fc2(x))
|
| 58 |
+
x = self.fc3(x)
|
| 59 |
+
return x
|
| 60 |
+
|
| 61 |
+
# Create an instance of the model
|
| 62 |
+
model = PopularityPredictor()
|
| 63 |
+
|
| 64 |
+
# Define the loss function and optimizer
|
| 65 |
+
criterion = nn.MSELoss()
|
| 66 |
+
optimizer = optim.Adam(model.parameters(), lr=0.001)
|
| 67 |
+
|
| 68 |
+
# Train the model
|
| 69 |
+
num_epochs = 100
|
| 70 |
+
for epoch in range(num_epochs):
|
| 71 |
+
model.train()
|
| 72 |
+
optimizer.zero_grad()
|
| 73 |
+
|
| 74 |
+
# Forward pass
|
| 75 |
+
outputs = model(X_train_tensor)
|
| 76 |
+
loss = criterion(outputs, y_train_tensor)
|
| 77 |
+
|
| 78 |
+
# Backward pass and optimization
|
| 79 |
+
loss.backward()
|
| 80 |
+
optimizer.step()
|
| 81 |
+
|
| 82 |
+
if (epoch+1) % 10 == 0:
|
| 83 |
+
print(f'Epoch [{epoch+1}/{num_epochs}], Loss: {loss.item():.4f}')
|
| 84 |
+
|
| 85 |
+
# Evaluate the model
|
| 86 |
+
model.eval()
|
| 87 |
+
with torch.no_grad():
|
| 88 |
+
predicted = model(X_test_tensor)
|
| 89 |
+
```
|
| 90 |
+
</details>
|