varshakolanu commited on
Commit
236612b
·
verified ·
1 Parent(s): aee9c54

Create model.py

Browse files
Files changed (1) hide show
  1. model.py +38 -0
model.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from sklearn.model_selection import train_test_split
3
+ from sklearn.ensemble import RandomForestRegressor # Example model
4
+ from sklearn.metrics import mean_squared_error
5
+ import joblib
6
+
7
+ # 1. Load your data
8
+ data = pd.read_csv('your_data.csv') # Replace with your data file
9
+
10
+ # 2. Preprocess the data
11
+ # (Add your data cleaning, transformation, and feature engineering steps here)
12
+ # Example:
13
+ # data['Delay_Days__c'] = data['Delay_Days__c'].fillna(0)
14
+ # data = pd.get_dummies(data, columns=['Quality_Report__c'])
15
+
16
+ # 3. Define features (X) and target (y)
17
+ # (Adjust these based on your actual column names)
18
+ X = data.drop(['Quality_Score__c', 'Timeliness_Score__c', 'Safety_Score__c', 'Communication_Score__c', 'Final_Score_c'], axis=1)
19
+ y = data[['Quality_Score__c', 'Timeliness_Score__c', 'Safety_Score__c', 'Communication_Score__c', 'Final_Score_c']]
20
+
21
+ # 4. Split data into training and testing sets
22
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
23
+
24
+ # 5. Choose a model
25
+ model = RandomForestRegressor(n_estimators=100, random_state=42) # Example: Random Forest
26
+
27
+ # 6. Train the model
28
+ model.fit(X_train, y_train)
29
+
30
+ # 7. Evaluate the model
31
+ y_pred = model.predict(X_test)
32
+ mse = mean_squared_error(y_test, y_pred)
33
+ print(f'Mean Squared Error: {mse}')
34
+
35
+ # 8. Save the model
36
+ joblib.dump(model, 'your_model.pkl') # Save the model to a file
37
+ print('Model saved to your_model.pkl')
38
+