Using scikit learn to predict good content on a website
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Predicting whether a page or article will perform well is a useful ranking problem, but only if "good content" is defined in measurable business terms. With scikit-learn, you can build a model that combines text features and metadata to estimate whether new content is likely to drive engagement, conversions, or retention.
Define The Label Before Writing Any Model Code
The first technical step is not model selection. It is deciding what good means. A practical label might be:
- '
1if an article exceeds a threshold for conversions, time on page, or return visits.' - '
0otherwise.'
That label should be created from data collected after publication, while the features should come only from information available before or at publish time. This separation prevents target leakage.
For example, you might start with a table like this:
Build A Mixed Text And Metadata Pipeline
Scikit-learn works well when you keep preprocessing and modeling inside one pipeline. For content prediction, a strong baseline is:
- '
TfidfVectorizerfor title and body text.' - '
OneHotEncoderfor categorical metadata.' - A simple classifier such as logistic regression.
This is not the final model, but it is a credible baseline that is easy to inspect and improve.
Predict Probabilities, Not Just Classes
Editorial teams usually benefit more from confidence scores than from yes-or-no labels:
A probability can feed content ranking, human review queues, or A/B testing decisions. It also makes threshold tuning easier when the cost of false positives and false negatives is asymmetric.
Evaluate The Right Metrics
Accuracy alone is usually not enough. If only 10 percent of articles count as good, a naive model that predicts 0 for everything can still look accurate.
Use metrics aligned with the business goal:
- Precision if editorial review time is limited and false positives are expensive.
- Recall if you want to catch as many high-potential articles as possible.
- ROC AUC or PR AUC when class balance is skewed.
Scikit-learn makes this easy:
Feature Ideas That Usually Help
Useful features often include readability scores, article age category, presence of code blocks, internal-link count, topic tags, and source channel. If you have historical ranking data, headline length and semantic embeddings may also help.
Start simple before reaching for deep learning. In many editorial systems, clean metadata and a strong baseline model outperform a more complex model trained on noisy labels.
Common Pitfalls
The biggest pitfall is label leakage. If you use page views, shares, or bounce rate as input features while also using them to define good, the model will appear excellent and be useless for pre-publication prediction.
Another common issue is training on too little data. Text models with many sparse features need enough examples to generalize. If your dataset is small, reduce feature complexity and focus on interpretable baselines.
Developers also often ignore drift. Content that performed well last year may not match current audience interests, search behavior, or platform changes. Retrain and re-evaluate regularly.
Finally, remember that "good content" is partly a product decision, not just a machine-learning task. The model only reflects the target you defined.
Summary
- Define
goodwith a measurable label before building the model. - Use only features available at prediction time to avoid leakage.
- A scikit-learn pipeline with TF-IDF, metadata, and logistic regression is a strong baseline.
- Predict probabilities so teams can rank and review content more effectively.
- Evaluate with metrics that match the editorial or business goal, not accuracy alone.
Related reading
- Using Silhouette Clustering in Spark
- Using sklearn cross_val_score and kfolds to fit and help predict model
- Using sklearn voting ensemble with partial fit
- Using Smote with Gridsearchcv in Scikit-learn
- Using TensorFlow through Jupyter Python 3
- Utility of parameter 'out' in numpy functions
- Using two values for one switch case statement
- Using variable in a LIMIT clause in MySQL

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.