Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

model_creation.py 2.4 KB

You have to be logged in to leave a comment. Sign In
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  1. from cmath import sqrt
  2. import mlflow
  3. import numpy as np
  4. import pandas as pd
  5. from sklearn.model_selection import train_test_split
  6. from sklearn.linear_model import ElasticNet
  7. import sys
  8. from sklearn.metrics import mean_absolute_error,mean_squared_error,r2_score
  9. from sklearn.ensemble import RandomForestClassifier
  10. def metrices(true_val,predicted):
  11. rmse=np.sqrt(mean_squared_error(true_val,predicted))
  12. mae=mean_absolute_error(true_val,predicted)
  13. r2=r2_score(true_val,predicted)
  14. return rmse,mae,r2
  15. if __name__=="__main__":
  16. dataset=pd.read_csv("cleaned_data.csv")
  17. X=dataset.drop(columns=["Loan_Status"])
  18. y=dataset['Loan_Status']
  19. X_train,X_test,y_train,y_test=train_test_split(X,y,shuffle=True,test_size=0.2)
  20. alpha=float(sys.argv[1]) if len(sys.argv[1])>1 else 0.5
  21. l1=float(sys.argv[2]) if len(sys.argv[2])>1 else 1
  22. with mlflow.start_run(run_name="another run") as run:
  23. model=ElasticNet(alpha=alpha,l1_ratio=l1)
  24. model.fit(X_train,y_train)
  25. model1=RandomForestClassifier()
  26. model1.fit (X_train,y_train)
  27. predict1=model.predict(X_test)
  28. predict=model.predict(X_test)
  29. rmse,mae,r2=metrices(y_test,predict)
  30. rmse1,mae1,r21=metrices(y_test,predict1)
  31. testing_acc_rf=model.score(X_test,y_test)
  32. training_acc=model.score(X_train,y_train)
  33. testing_acc=model.score(X_test,y_test)
  34. mlflow.log_metric("RMSE",rmse)
  35. mlflow.log_metric("MAE",mae)
  36. mlflow.log_metric("R2",r2)
  37. mlflow.log_metric("RMSE1",rmse1)
  38. mlflow.log_metric("MAE1",mae1)
  39. mlflow.log_metric("R21",r21)
  40. mlflow.log_param("Alpha",alpha)
  41. mlflow.log_param("l1_ratio",l1)
  42. mlflow.log_metric("Training Accuracy",training_acc)
  43. mlflow.log_metric("Testing Accuracy",testing_acc)
  44. mlflow.log_metric("the randomforest acc",testing_acc_rf)
  45. # remote_server_uri="https://dagshub.com/naimurborno/Loan_prediction_tracking_using_mlflow.mlflow"
  46. # mlflow.set_tracking_uri(remote_server_uri)
  47. #for using mlflow using AWS
  48. remote_server_uri="http://ec2-54-175-131-61.compute-1.amazonaws.com:5000/"
  49. mlflow.set_tracking_uri(remote_server_uri)
  50. mlflow.sklearn.log_model(model,"ElasticNet Model",registered_model_name="ElasticNet Model")
  51. #mlflow.skleran.log_model(model1,"RandomForestClassifier")
  52. #this is good
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...