FM
MLSEO Podcast ft. Isaías Blanco
Escucha todos contenidos en una sola página. En Spotify conseguirás el último episodio publicado, mientras que YouTube va del primero al último para quiénes nos descubren gracias al SEO.
A Trusted Machine Learning SEO podcast
The following code provides a complete example of how to create a machine-learning model using synthetic data to predict the number of podcast plays based on positive comments.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
# Step 1: Generate synthetic data
np.random.seed(42) # For reproducibility
n_samples = 100
# Generate random positive comments
positive_comments = np.random.randint(0, 100, size=n_samples)
# Generate podcast plays based on a linear relationship with some noise
# Let's assume that each positive comment contributes to an average of 10 plays
plays = positive_comments * 10 + np.random.normal(0, 20, size=n_samples) # Adding some noise
# Create a DataFrame
data = {
'positive_comments': positive_comments,
'podcast_plays': plays
}
df = pd.DataFrame(data)
# Step 2: Data preprocessing
X = df[['positive_comments']]
y = df['podcast_plays']
# Splitting the dataset
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Step 3: Model training
model = LinearRegression()
model.fit(X_train, y_train)
# Step 4: Model evaluation
y_pred = model.predict(X_test)
# Calculate metrics
mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)
print(f'Mean Squared Error: {mse:.2f}')
print(f'R^2 Score: {r2:.2f}')
# Step 5: Visualization
plt.scatter(df['positive_comments'], df['podcast_plays'], color='blue', label='Actual Data')
plt.scatter(X_test, y_pred, color='red', label='Predicted Data')
plt.plot(X_test, y_pred, color='green', linewidth=2, label='Regression Line')
plt.title('Podcast Plays vs Positive Comments')
plt.xlabel('Number of Positive Comments')
plt.ylabel('Number of Podcast Plays')
plt.legend()
plt.show()