4  Menggunakan Media Sosial

To insert a logo into your Quarto website’s navigation menu, you need to modify the _quarto.yml configuration file. The logo typically appears to the left of the website title in the top navigation bar (navbar) or at the top of a sidebar. [1, 2]

5 Penjelasan Matriks

5.1 1. Definisi Matriks

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, confusion_matrix, ConfusionMatrixDisplay
from sklearn.decomposition import PCA

# Set style visualisasi
plt.style.use('seaborn-v0_8-whitegrid')
sns.set_palette("Set2")

# 1. Memuat Dataset Iris
iris = datasets.load_iris()
X = iris.data
y = iris.target
feature_names = iris.feature_names
target_names = iris.target_names

# 2. Train-Test Split (Menggunakan Integer untuk keamanan)
# Dataset Iris memiliki 150 sampel, 20% = 30 sampel
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=30, random_state=42, stratify=y
)

# 3. Pelatihan Model
model = LogisticRegression(max_iter=200)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)

# 4. Visualisasi
fig, axes = plt.subplots(2, 2, figsize=(14, 12))

# Scatter plot: Sepal
ax = axes[0, 0]
for class_idx, name in enumerate(target_names):
    ax.scatter(X[y == class_idx, 0], X[y == class_idx, 1], 
               label=name, edgecolors='k', s=50, alpha=0.7)
ax.set_xlabel(feature_names[0])
ax.set_ylabel(feature_names[1])
ax.set_title('Sepal Length vs Sepal Width')
ax.legend()
ax.grid(True, alpha=0.3)

# Scatter plot: Petal
ax = axes[0, 1]
for class_idx, name in enumerate(target_names):
    ax.scatter(X[y == class_idx, 2], X[y == class_idx, 3], 
               label=name, edgecolors='k', s=50, alpha=0.7)
ax.set_xlabel(feature_names[2])
ax.set_ylabel(feature_names[3])
ax.set_title('Petal Length vs Petal Width')
ax.legend()
ax.grid(True, alpha=0.3)

# Decision Boundary
ax = axes[1, 0]
X_2feat = X[:, :2]
model_2 = LogisticRegression(max_iter=200)
model_2.fit(X_2feat, y)

h = 0.02
x_min, x_max = X_2feat[:, 0].min() - 1, X_2feat[:, 0].max() + 1
y_min, y_max = X_2feat[:, 1].min() - 1, X_2feat[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
                     np.arange(y_min, y_max, h))
Z = model_2.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)

ax.contourf(xx, yy, Z, alpha=0.3, cmap='Set2')
for class_idx, name in enumerate(target_names):
    ax.scatter(X_2feat[y == class_idx, 0], X_2feat[y == class_idx, 1], 
               label=name, edgecolors='k', s=50)
ax.set_xlabel(feature_names[0])
ax.set_ylabel(feature_names[1])
ax.set_title('Decision Boundary')
ax.legend()
ax.grid(True, alpha=0.3)

# Confusion Matrix
ax = axes[1, 1]
cm = confusion_matrix(y_test, y_pred)
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=target_names)
disp.plot(ax=ax, cmap='Blues', values_format='d')
ax.set_title('Confusion Matrix')

plt.tight_layout()
plt.show()

# PCA Visualization
pca = PCA(n_components=2)
X_pca = pca.fit_transform(X)

plt.figure(figsize=(8, 6))
for class_idx, name in enumerate(target_names):
    plt.scatter(X_pca[y == class_idx, 0], X_pca[y == class_idx, 1], 
                label=name, edgecolors='k', s=60, alpha=0.7)
plt.xlabel(f'PC1 ({pca.explained_variance_ratio_[0]:.2%})')
plt.ylabel(f'PC2 ({pca.explained_variance_ratio_[1]:.2%})')
plt.title('PCA Projection')
plt.legend()
plt.grid(True, alpha=0.3)
plt.show()

# Print Metrics
print(f"Akurasi: {accuracy_score(y_test, y_pred):.4f}")

Embedded Sage Cells

Your own computations

Type your own Sage computation below and click “Evaluate”.

6 Baru ini mencoba

Factorial

Click the “Activate” button below to calculate factorials.

7

7.1 4. Implementasi di SageMath

# Membuat matriks 3x4
A = matrix([[1, 2, 3, 4],
            [5, 6, 7, 8],
            [9, 10, 11, 12]])
show("Matriks A:", A)

# Operasi dasar
B = matrix([[2, 0, 1, 3],
            [1, 1, 0, 2],
            [0, 2, 1, 1]])

show("A + B:", A + B)
show("2 * A:", 2 * A)
show("Transpose A:", A.transpose())

# Akses elemen dan slice
print("Elemen [baris-1, kolom-2]:", A[0, 1])  # Output: 2
show("Submatriks (2 baris pertama, kolom 2-3):", A[0:2, 1:3])

# Matriks persegi untuk operasi lanjut
C = matrix([[4, 2], [3, 1]])
show("Determinan C:", C.determinant())
show("Invers C:", C.inverse())
show("C * C^-1:", C * C.inverse())  # Harus menghasilkan matriks identitas

7.2

7.3 1. Adding a Logo to the Top Navigation Bar (Navbar)

To place a logo in the main top-level navigation, use the logo option under the navbar key in your _quarto.yml: [3, 4, 5]

website:
  navbar:
    logo: "images/logo.png"
    logo-alt: "Description of the logo for accessibility"
    logo-href: "index.qmd" # Target link when clicking the logo (defaults to home)
    title: "My Website"
    left:
      - text: "Home"
        href: index.qmd

7.4 2. Adding a Logo to the Sidebar

If your site uses a sidebar for navigation, you can also define a logo specifically for that area: [6, 7, 8]

website:
  sidebar:
    logo: "images/sidebar-logo.png"
    logo-alt: "Sidebar logo description"
    title: "Sidebar Title"

7.5 3. Using Brand.yml for Multiformat Logos [9]

For more advanced setups, such as different logos for light and dark modes or different sizes, you can use a _brand.yml file: [10, 11]

  • Define in _brand.yml:

    logo:
      medium:
        light: "images/logo-light.png"
        dark: "images/logo-dark.png"
  • Reference in _quarto.yml:

    brand: _brand.yml
    website:
      navbar:
        logo: medium # Quarto automatically picks the correct light/dark version

    [12]

7.9 3. Adding to Sidebar Contents

If you want Instagram to appear as a regular menu item among your page links:

website:
  sidebar:
    contents:
      - section: "Social Media"
        contents:
          - text: "Instagram"
            icon: instagram # Adds the icon next to the text
            href: https://www.instagram.com

Key Details:

  • Icon: Use instagram for the standard Bootstrap icon.

  • Href: Ensure you use the full URL starting with https://.

  • Position: Tools will always appear at the top of the sidebar, while footers appear at the bottom. [1, 4, 5]

Would you like to know how to change the color of the Instagram icon to match the brand’s original purple/pink?

[1] https://quarto.org

[2] https://quarto.org

[3] https://www.youtube.com

[4] https://quarto.org

[5] https://quarto.org