Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:666ghj BettaFish scikit learn

From Leeroopedia
Knowledge Sources
Domains Machine_Learning, NLP
Last Updated 2026-10-08 21:30 GMT

Overview

scikit-learn machine learning library for training and evaluating classical ML sentiment models (Naive Bayes, SVM, XGBoost, LSTM, BERT) and KMeans clustering.

Description

This environment provides the scikit-learn library used by BettaFish's classical ML sentiment analysis pipeline. It powers the SentimentModel trainer (Naive Bayes, SVM, XGBoost classifiers) and the SentimentPredictor (unified multi-model predictor). It is also used for KMeans clustering in the Diversity_Sampling component and for model evaluation (accuracy_score, f1_score, classification_report). The library provides train/test splitting and model serialization utilities.

Usage

Use this environment for classical ML sentiment model training, evaluation, and KMeans-based diversity sampling. It is required by SentimentModel_train_and_evaluate and SentimentPredictor_predict.

System Requirements

Category Requirement Notes
OS Linux, macOS, Windows Pure Python package
Hardware CPU sufficient No GPU required
Disk <1GB For scikit-learn + dependencies

Dependencies

System Packages

  • None beyond Python runtime

Python Packages

  • `scikit-learn` >= 1.3.0 (main requirements.txt)
  • `scikit-learn` >= 0.23.2 (MachineLearning requirements.txt)
  • `xgboost` >= 2.0.0 (main), >= 1.2.1 (MachineLearning)
  • `numpy` >= 1.24.0
  • `pandas` >= 2.0.0
  • `jieba` == 0.42.1 (Chinese text segmentation)

Credentials

No credentials required.

Quick Install

pip install scikit-learn>=1.3.0 xgboost>=2.0.0 jieba==0.42.1

Code Evidence

Model evaluation using scikit-learn from `SentimentAnalysisModel/WeiboSentiment_MachineLearning/base_model.py:44-60`:

from sklearn.metrics import accuracy_score, f1_score, classification_report
from sklearn.model_selection import train_test_split

def evaluate(self, test_data: List[Tuple[str, int]]) -> Dict[str, float]:
    texts = [item[0] for item in test_data]
    labels = [item[1] for item in test_data]
    predictions = self.predict(texts)
    accuracy = accuracy_score(labels, predictions)
    f1 = f1_score(labels, predictions, average='weighted')
    print(f"准确率: {accuracy:.4f}")
    print(f"F1分数: {f1:.4f}")

KMeans clustering from `InsightEngine/agent.py:160-162`:

from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=n_clusters, random_state=42, n_init=10)
labels = kmeans.fit_predict(embeddings)

Common Errors

Error Message Cause Solution
`ImportError: No module named 'sklearn'` scikit-learn not installed `pip install scikit-learn>=1.3.0`
`ValueError: n_samples=1` Too few samples for KMeans Ensure at least 2 clusters' worth of data
`ModuleNotFoundError: No module named 'xgboost'` XGBoost not installed `pip install xgboost>=2.0.0`

Compatibility Notes

  • Version disparity: Main requirements specify `scikit-learn >= 1.3.0`; MachineLearning module requires `>= 0.23.2`. Use the higher version for full compatibility.
  • jieba: Required for Chinese text segmentation. Pinned to `0.42.1` across all requirements files.
  • CPU-only: All scikit-learn operations run on CPU; no CUDA support needed.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment