Example 00
beginner
00
Tensors
DataFrame
ML
Preprocessing

Quick Start Guide

A rapid introduction to Deepbox's core features — tensors, DataFrames, and machine learning in under 50 lines. This example uses deepbox/ndarray, deepbox/dataframe, deepbox/ml, deepbox/preprocess and focuses on Tensor creation, addition, mean; DataFrame creation, display; LinearRegression (fit, predict); trainTestSplit.

Deepbox Modules Used

deepbox/ndarraydeepbox/dataframedeepbox/mldeepbox/preprocess

What You Will Learn

  • Use deepbox/ndarray for Tensor creation, addition, mean.
  • Use deepbox/dataframe for DataFrame creation, display.
  • Use deepbox/ml for LinearRegression (fit, predict).
  • Use deepbox/preprocess for trainTestSplit.
  • A rapid introduction to Deepbox's core features — tensors, DataFrames, and machine learning in under 50 lines.

Source Files

index.ts
1/**2 * Quick Start Guide3 *4 * A rapid introduction to Deepbox's core features.5 * Run this first to get a feel for the framework!6 */78import { DataFrame } from "deepbox/dataframe";9import { LinearRegression } from "deepbox/ml";10import { add, mean, tensor } from "deepbox/ndarray";11import { trainTestSplit } from "deepbox/preprocess";1213console.log("🚀 Welcome to Deepbox!\n");1415// 1. Tensors (N-dimensional arrays)16console.log("1️⃣  Tensors:");17const a = tensor([1, 2, 3, 4, 5]);18const b = tensor([10, 20, 30, 40, 50]);19const c = add(a, b);20console.log("   a + b =", c.toString());21console.log("   mean(a) =", `${mean(a).toString()}\n`);2223// 2. DataFrames (tabular data)24console.log("2️⃣  DataFrames:");25const df = new DataFrame({26  name: ["Alice", "Bob", "Charlie"],27  age: [25, 30, 35],28  score: [85, 90, 78],29});30console.log(`${df.toString()}\n`);3132// 3. Machine Learning33console.log("3️⃣  Machine Learning:");3435// Generate simple data: y = 2x + 136const X = tensor([[1], [2], [3], [4], [5], [6], [7], [8]]);37const y = tensor([3, 5, 7, 9, 11, 13, 15, 17]);3839const [X_train, X_test, y_train, y_test] = trainTestSplit(X, y, {40  testSize: 0.25,41  randomState: 42,42});4344const model = new LinearRegression();45model.fit(X_train, y_train);46const predictions = model.predict(X_test);4748console.log("   Trained linear regression model");49console.log("   Predictions:", predictions.toString());50console.log("   Actual:     ", y_test.toString());5152console.log("\n✨ That's Deepbox in a nutshell!");53console.log("📖 Explore the numbered examples (01-49) to learn more.");54console.log("💡 Each example focuses on a specific feature with detailed comments.\n");55

Console Output

$ npx tsx 00-quick-start/index.ts
Console output demonstrating tensors, DataFrames, and linear regression predictions