Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -52,11 +52,12 @@ def train_the_model(data):
|
|
| 52 |
xgb_model.fit(X_new, y_new)
|
| 53 |
dump(xgb_model,'xgb_model.joblib')
|
| 54 |
|
| 55 |
-
|
| 56 |
y_pred = xgb_model.predict(X_test)
|
| 57 |
accuracy = accuracy_score(y_test, y_pred)
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
except:
|
| 62 |
data = data
|
|
@@ -113,11 +114,6 @@ def train_the_model(data):
|
|
| 113 |
accuracy = accuracy_score(y_test, y_pred)
|
| 114 |
classification_rep = classification_report(y_test, y_pred)
|
| 115 |
|
| 116 |
-
# Print the results
|
| 117 |
-
print("Accuracy:", accuracy)
|
| 118 |
-
print("Classification Report:\n", classification_report(y_test, y_pred))
|
| 119 |
-
|
| 120 |
-
|
| 121 |
# Save the model
|
| 122 |
model_filename = 'xgb_model.joblib'
|
| 123 |
dump(best_xgb, model_filename)
|
|
@@ -126,9 +122,7 @@ def train_the_model(data):
|
|
| 126 |
encoders_filename = 'encoders.joblib'
|
| 127 |
dump(encoders, encoders_filename)
|
| 128 |
|
| 129 |
-
|
| 130 |
-
print(f"Encoders saved as {encoders_filename}")
|
| 131 |
-
print("new base model trained")
|
| 132 |
|
| 133 |
@app.get("/trigger_the_data_fecher")
|
| 134 |
async def your_continuous_function(page: int,paginate: int,Tenant: str):
|
|
@@ -164,9 +158,9 @@ async def your_continuous_function(page: int,paginate: int,Tenant: str):
|
|
| 164 |
print("data collected from page : "+str(page))
|
| 165 |
#data.to_csv("new.csv")
|
| 166 |
|
| 167 |
-
train_the_model(data)
|
| 168 |
|
| 169 |
-
return {"
|
| 170 |
|
| 171 |
|
| 172 |
|
|
|
|
| 52 |
xgb_model.fit(X_new, y_new)
|
| 53 |
dump(xgb_model,'xgb_model.joblib')
|
| 54 |
|
| 55 |
+
|
| 56 |
y_pred = xgb_model.predict(X_test)
|
| 57 |
accuracy = accuracy_score(y_test, y_pred)
|
| 58 |
+
classification_rep = classification_report(y_test, y_pred)
|
| 59 |
+
return accuracy,classification_rep,"Model finetuned with new data."
|
| 60 |
+
|
| 61 |
|
| 62 |
except:
|
| 63 |
data = data
|
|
|
|
| 114 |
accuracy = accuracy_score(y_test, y_pred)
|
| 115 |
classification_rep = classification_report(y_test, y_pred)
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
# Save the model
|
| 118 |
model_filename = 'xgb_model.joblib'
|
| 119 |
dump(best_xgb, model_filename)
|
|
|
|
| 122 |
encoders_filename = 'encoders.joblib'
|
| 123 |
dump(encoders, encoders_filename)
|
| 124 |
|
| 125 |
+
return accuracy,classification_rep,"base Model trained"
|
|
|
|
|
|
|
| 126 |
|
| 127 |
@app.get("/trigger_the_data_fecher")
|
| 128 |
async def your_continuous_function(page: int,paginate: int,Tenant: str):
|
|
|
|
| 158 |
print("data collected from page : "+str(page))
|
| 159 |
#data.to_csv("new.csv")
|
| 160 |
|
| 161 |
+
accuracy,classification_rep,message = train_the_model(data)
|
| 162 |
|
| 163 |
+
return {"message":message,"page_number":page,"data_count":data_count,"accuracy":accuracy,"classification_rep":classification_rep}
|
| 164 |
|
| 165 |
|
| 166 |
|