|
|
|
import pandas as pd |
|
import numpy as np |
|
from sklearn.ensemble import RandomForestRegressor |
|
from sklearn.model_selection import train_test_split |
|
from sklearn.metrics import r2_score |
|
import joblib |
|
|
|
|
|
np.random.seed(42) |
|
size = 200 |
|
data = { |
|
"mean_intensity": np.random.uniform(0.2, 0.5, size), |
|
"bbox_width": np.random.uniform(0.05, 0.2, size), |
|
"bbox_height": np.random.uniform(0.05, 0.2, size), |
|
"eye_dist": np.random.uniform(0.2, 0.5, size), |
|
"nose_len": np.random.uniform(0.2, 0.5, size), |
|
"jaw_width": np.random.uniform(0.2, 0.5, size), |
|
"avg_skin_tone": np.random.uniform(0.2, 0.5, size), |
|
"hemoglobin": np.random.uniform(10.5, 17.5, size) |
|
} |
|
df = pd.DataFrame(data) |
|
|
|
|
|
df.to_csv("hemoglobin_dataset.csv", index=False) |
|
|
|
|
|
X = df.drop(columns=["hemoglobin"]) |
|
y = df["hemoglobin"] |
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) |
|
|
|
|
|
model = RandomForestRegressor(n_estimators=100, random_state=42) |
|
model.fit(X_train, y_train) |
|
|
|
|
|
y_pred = model.predict(X_test) |
|
print("R2 Score:", r2_score(y_test, y_pred)) |
|
|
|
|
|
joblib.dump(model, "hemoglobin_model.pkl") |
|
print("Model saved as hemoglobin_model.pkl") |
|
|