| import pandas as pd |
| import pickle |
| import skops.io as sio |
|
|
|
|
| |
| model = sio.load("cpu_price_model.skops") |
|
|
|
|
| |
| with open("feature_names.pkl", "rb") as f: |
| feature_names = pickle.load(f) |
|
|
|
|
| |
| def predict_cpu_price(features: dict) -> float: |
| """ |
| Predict CPU price from input features. |
| |
| Args: |
| features (dict): Dictionary containing all required features. |
| |
| Returns: |
| float: Predicted CPU price. |
| """ |
|
|
| df = pd.DataFrame([features]) |
|
|
| missing_features = set(feature_names) - set(df.columns) |
|
|
| if missing_features: |
| raise ValueError( |
| f"Missing features: {missing_features}" |
| ) |
|
|
| df = df[feature_names] |
| |
| prediction = model.predict(df) |
|
|
| return float(prediction[0]) |
|
|
|
|
| |
| if __name__ == "__main__": |
|
|
| sample_input = { |
| "tdp": 125, |
| "cores": 8, |
| "logicals": 16, |
| "cpuCount": 1, |
| "rank": 2500, |
| "samples": 120, |
| "extracted_ghz": 3.6, |
| "speed_ghz": 3.6, |
| "turbo_ghz": 5.0, |
| "cost_per_rank_point": 0.12, |
| "cost_per_core": 45.5, |
| "brand_encoded": 0, |
| "category_final_encoded": 1, |
| "socket_final_encoded": 3 |
| } |
|
|
| predicted_price = predict_cpu_price(sample_input) |
|
|
| print(f"Predicted CPU Price: ${predicted_price:.2f}") |