Navya-Sree's picture
Create create_model.py
16a4a1b verified
from sklearn.ensemble import RandomForestClassifier
from sklearn.preprocessing import StandardScaler
import pandas as pd
import joblib
import numpy as np
# Create sample hospital data
data = {
'age': [65, 72, 58, 81, 45],
'time_in_hospital': [5, 8, 3, 12, 4],
'num_lab_procedures': [45, 32, 28, 51, 38],
'num_medications': [15, 22, 8, 18, 12],
'readmitted': [1, 1, 0, 1, 0]
}
df = pd.DataFrame(data)
# Prepare features and target
X = df.drop('readmitted', axis=1)
y = df['readmitted']
# Create and train a simple model
model = RandomForestClassifier(n_estimators=10)
model.fit(X, y)
# Create and fit a preprocessor
preprocessor = StandardScaler()
preprocessor.fit(X)
# Save valid files
joblib.dump(model, 'model.joblib', compress=3)
joblib.dump(preprocessor, 'preprocessor.pkl', compress=3)
print("Created valid model.joblib and preprocessor.pkl files!")
print(f"Model size: {os.path.getsize('model.joblib')} bytes")
print(f"Preprocessor size: {os.path.getsize('preprocessor.pkl')} bytes")