Code Lab
🏠 Home
⚡ Code Lab
🧠 ML Studio
🔧 ML Tools
📚 LMS ↗
🌙
☰
⚙️ scikit-learn
Theme: Dracula
Material Dark
Nord
Default
Auto-run on Ctrl+Enter
🗑 Clear
📋 Copy
🔗 Share
▶ Run
# scikit-learn — Machine Learning import numpy as np from sklearn.datasets import make_classification from sklearn.model_selection import train_test_split, cross_val_score from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LogisticRegression from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import accuracy_score, classification_report # Generate dataset X, y = make_classification(n_samples=500, n_features=10, n_informative=6, random_state=42) X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, random_state=42) # Preprocess scaler = StandardScaler() X_train_s = scaler.fit_transform(X_train) X_test_s = scaler.transform(X_test) # Train & evaluate both models for name, clf in [ ("Logistic Regression", LogisticRegression()), ("Random Forest", RandomForestClassifier(n_estimators=50, random_state=42)) ]: clf.fit(X_train_s, y_train) acc = accuracy_score(y_test, clf.predict(X_test_s)) cv = cross_val_score(clf, X_train_s, y_train, cv=5).mean() print(f"{name}: Test Acc={acc*100:.1f}% CV={cv*100:.1f}%")
OUTPUT
Ready
✕ Clear
▶ Press Run or Ctrl+Enter to execute your code.
✕
🏠 Home
⚡ Code Lab
🧠 ML Studio
🔧 ML Tools