Spaces:
Running
Running
File size: 1,273 Bytes
fc3c462 4892e5e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from fastapi import FastAPI
import joblib
import uvicorn
app = FastAPI()
model = joblib.load('ridge_model.pkl')
poly = joblib.load('polynomial_transformer.pkl')
def predict_corrected_rank(percentile: float, total_candidates: int) -> float:
# Calculate initial predicted rank using the formula
predicted_rank = ((100 - percentile) * total_candidates) / 100
# Predict correction factor using the polynomial regression model
percentile_poly = poly.transform([[percentile]])
predicted_correction = model.predict(percentile_poly)[0][0]
# Adjust the predicted rank with the correction factor
corrected_rank = predicted_rank + predicted_correction
# Ensure the rank does not exceed the total number of candidates or become negative
corrected_rank = max(1, min(corrected_rank, total_candidates))
return round(corrected_rank)
@app.get("/predict")
def get_corrected_rank(percentile: float, total_candidates: int):
corrected_rank = predict_corrected_rank(percentile, total_candidates)
return {"percentile": percentile, "total_candidates": total_candidates, "corrected_rank": corrected_rank}
if __name__ == "__main__":
# logger.info("Starting PreCollege Data Scraper Server...")
uvicorn.run(app, host="0.0.0.0", port=7860) |