Instructions to use verisimb/regresi with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use verisimb/regresi with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("verisimb/regresi", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
🌸 Iris Petal Width — Linear Regression Model
Model Multiple Linear Regression yang dilatih untuk memprediksi lebar petal (petal width) bunga Iris berdasarkan tiga fitur morfologi bunga dari dataset Iris klasik (R.A. Fisher, 1936).
📋 Informasi Model
| Atribut | Detail |
|---|---|
| Tipe Model | Multiple Linear Regression |
| Library | scikit-learn |
| Task | Tabular Regression |
| Dataset | Iris Dataset (UCI Repository) |
| File Model | iris_linear_regression_model.pkl |
| Format | joblib pickle (.pkl) |
📊 Performa Model
Evaluasi dilakukan pada 30 data uji (20% dari total 150 sampel):
| Metrik | Nilai |
|---|---|
| R² Score | 0.9269 |
| MSE (Mean Sq. Error) | 0.0464 |
| RMSE (Root MSE) | 0.2155 |
R² = 0.9269 artinya model mampu menjelaskan 92.69% variasi data petal width — performa yang sangat baik untuk model linear.
📐 Formula Regresi
Model menghasilkan persamaan regresi berikut:
petal_width = -0.1791
+ (-0.2379 × sepal_length)
+ ( 0.2430 × sepal_width)
+ ( 0.5367 × petal_length)
Koefisien Detail
| Fitur | Koefisien | Interpretasi |
|---|---|---|
sepal_length |
-0.2379 | Tiap +1 cm sepal length → petal width turun 0.24 cm |
sepal_width |
0.2430 | Tiap +1 cm sepal width → petal width naik 0.24 cm |
petal_length |
0.5367 | Tiap +1 cm petal length → petal width naik 0.54 cm |
| Intercept | -0.1791 | Nilai dasar saat semua fitur = 0 |
Petal length adalah prediktor terkuat dengan koefisien terbesar (0.5367), sejalan dengan korelasi tinggi (0.9490) yang tercatat dalam dataset.
🗂️ Dataset
- Nama: Iris Plants Database
- Sumber: UCI Machine Learning Repository
- Dibuat oleh: R.A. Fisher (1936)
- Jumlah sampel: 150 (50 per kelas)
- Kelas: Iris Setosa, Iris Versicolour, Iris Virginica
- Missing values: Tidak ada
Statistik Ringkas Dataset
| Fitur | Min | Max | Mean | Std Dev |
|---|---|---|---|---|
sepal_length |
4.3 | 7.9 | 5.84 | 0.83 |
sepal_width |
2.0 | 4.4 | 3.05 | 0.43 |
petal_length |
1.0 | 6.9 | 3.76 | 1.76 |
petal_width |
0.1 | 2.5 | 1.20 | 0.76 |
Split Data
| Set | Jumlah Sampel |
|---|---|
| Training | 120 (80%) |
| Testing | 30 (20%) |
Split menggunakan
random_state=42untuk reproducibility.
🚀 Cara Menggunakan Model
Install Dependensi
pip install scikit-learn joblib huggingface_hub
Load & Prediksi
import joblib
import numpy as np
from huggingface_hub import hf_hub_download
# Download model dari Hugging Face
model_path = hf_hub_download(
repo_id="verisimb/regresi",
filename="iris_linear_regression_model.pkl",
)
model = joblib.load(model_path)
# Prediksi satu sampel: [sepal_length, sepal_width, petal_length]
sample = [[5.1, 3.5, 1.4]]
prediction = model.predict(sample)
print(f"Prediksi Petal Width: {prediction[0]:.4f} cm")
# Output: Prediksi Petal Width: 0.2095 cm
Prediksi Batch
import pandas as pd
data_baru = pd.DataFrame({
'sepal_length': [5.1, 6.3, 7.2],
'sepal_width' : [3.5, 2.9, 3.0],
'petal_length': [1.4, 4.5, 5.8]
})
predictions = model.predict(data_baru)
data_baru['petal_width_pred'] = predictions.round(4)
print(data_baru)
Output:
sepal_length sepal_width petal_length petal_width_pred
0 5.1 3.5 1.4 0.2095
1 6.3 2.9 4.5 1.4421
2 7.2 3.0 5.8 1.9500
Rentang Input yang Valid
| Fitur | Min | Max | Satuan |
|---|---|---|---|
sepal_length |
4.3 | 7.9 | cm |
sepal_width |
2.0 | 4.4 | cm |
petal_length |
1.0 | 6.9 | cm |
🔧 Detail Training
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import joblib
# Features dan Target
X = df[['sepal_length', 'sepal_width', 'petal_length']]
y = df['petal_width']
# Split data
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
# Training
model = LinearRegression()
model.fit(X_train, y_train)
# Simpan model
joblib.dump(model, "iris_linear_regression_model.pkl")
Notebook lengkap proses pelatihan tersedia di: Linear_Regression_Iris.ipynb
🌐 Demo Interaktif
Coba model langsung melalui aplikasi Gradio yang telah di-deploy:
📁 File dalam Repository
| File | Deskripsi |
|---|---|
iris_linear_regression_model.pkl |
File model terlatih (joblib format) |
✍️ Informasi
- Author: verisimb
- Mata Kuliah: Pemrograman Web Framework — Semester 4
- Downloads last month
- -
Evaluation results
- R² Score on Iris Dataset (UCI)self-reported0.927
- Mean Squared Error on Iris Dataset (UCI)self-reported0.046
- Root Mean Squared Error on Iris Dataset (UCI)self-reported0.215