47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
import numpy as np
|
|
import tensorflow as tf
|
|
from tensorflow import keras
|
|
from keras.layers import Conv2D, Dense, Embedding, Flatten, LSTM, MaxPooling2D
|
|
from keras.models import Sequential
|
|
from xgboost import XGBClassifier
|
|
|
|
# (a) Prediksi Stok Barang (LSTM)
|
|
# Input shape: (samples, time_steps=12, features=1)
|
|
model_a = Sequential([
|
|
LSTM(32, input_shape=(12, 1)),
|
|
Dense(1)
|
|
])
|
|
model_a.compile(optimizer='adam', loss='mse')
|
|
|
|
# (b) Klasifikasi Foto Produk Rusak vs Normal (CNN)
|
|
# Input shape contoh citra RGB 128x128
|
|
model_b = Sequential([
|
|
Conv2D(32, (3, 3), activation='relu', input_shape=(128, 128, 3)),
|
|
MaxPooling2D((2, 2)),
|
|
Flatten(),
|
|
Dense(64, activation='relu'),
|
|
Dense(1, activation='sigmoid') # binary: rusak vs normal
|
|
])
|
|
model_b.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
|
|
|
|
# (c) Analisis Sentimen Ulasan Play Store (LSTM + Embedding)
|
|
vocab_size = 5000
|
|
max_length = 100
|
|
|
|
model_c = Sequential([
|
|
Embedding(input_dim=vocab_size, output_dim=64, input_length=max_length),
|
|
LSTM(64),
|
|
Dense(32, activation='relu'),
|
|
Dense(1, activation='sigmoid') # binary: positif vs negatif
|
|
])
|
|
model_c.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
|
|
|
|
# (d) Prediksi Churn Pelanggan Tabular (ML Klasik - XGBoost)
|
|
# X_train memiliki dimensi (n_samples, 15)
|
|
model_d = XGBClassifier(
|
|
n_estimators=100,
|
|
max_depth=4,
|
|
learning_rate=0.1,
|
|
random_state=42
|
|
)
|
|
# model_d.fit(X_train, y_train) |