Skip to content

Commit

Permalink
model training is done
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnysavita10 committed Aug 24, 2024
1 parent 344a9b0 commit 90ce3b6
Show file tree
Hide file tree
Showing 22 changed files with 44,488 additions and 6 deletions.
11,056 changes: 11,056 additions & 0 deletions Artifacts/08_24_2024_13_18_42/data_ingestion/feature_store/NetworkData.csv

Large diffs are not rendered by default.

2,212 changes: 2,212 additions & 0 deletions Artifacts/08_24_2024_13_18_42/data_ingestion/ingested/test.csv

Large diffs are not rendered by default.

8,845 changes: 8,845 additions & 0 deletions Artifacts/08_24_2024_13_18_42/data_ingestion/ingested/train.csv

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Abnormal_URL:
drift_status: false
p_value: 0.9998299425911609
DNSRecord:
drift_status: false
p_value: 1.0
Domain_registeration_length:
drift_status: false
p_value: 0.9999998996954222
Favicon:
drift_status: false
p_value: 0.9371431479914312
Google_Index:
drift_status: false
p_value: 0.9999996521355587
HTTPS_token:
drift_status: false
p_value: 0.9970105474352128
Iframe:
drift_status: false
p_value: 0.9943908690886974
Links_in_tags:
drift_status: false
p_value: 0.9659080032037665
Links_pointing_to_page:
drift_status: false
p_value: 1.0
Page_Rank:
drift_status: false
p_value: 0.9998299425911609
Prefix_Suffix:
drift_status: false
p_value: 0.9999999999598222
Redirect:
drift_status: false
p_value: 1.0
Request_URL:
drift_status: false
p_value: 0.9925611176019148
Result:
drift_status: false
p_value: 1.0
RightClick:
drift_status: false
p_value: 1.0
SFH:
drift_status: false
p_value: 1.0
SSLfinal_State:
drift_status: false
p_value: 0.971456534142284
Shortining_Service:
drift_status: false
p_value: 0.9999953843756324
Statistical_report:
drift_status: false
p_value: 1.0
Submitting_to_email:
drift_status: false
p_value: 0.9844261985874094
URL_Length:
drift_status: false
p_value: 0.8979221700912247
URL_of_Anchor:
drift_status: false
p_value: 0.9943908690886974
age_of_domain:
drift_status: false
p_value: 0.9597114153770513
double_slash_redirecting:
drift_status: false
p_value: 0.9739932435377546
having_At_Symbol:
drift_status: false
p_value: 0.9860900857001905
having_IP_Address:
drift_status: false
p_value: 0.5890956201196135
having_Sub_Domain:
drift_status: false
p_value: 0.971456534142284
on_mouseover:
drift_status: false
p_value: 0.8979221700912247
popUpWidnow:
drift_status: false
p_value: 0.7786069254909116
port:
drift_status: false
p_value: 0.98068847421368
web_traffic:
drift_status: false
p_value: 0.7247242015659158
11,056 changes: 11,056 additions & 0 deletions Artifacts/08_24_2024_13_22_11/data_ingestion/feature_store/NetworkData.csv

Large diffs are not rendered by default.

2,212 changes: 2,212 additions & 0 deletions Artifacts/08_24_2024_13_22_11/data_ingestion/ingested/test.csv

Large diffs are not rendered by default.

8,845 changes: 8,845 additions & 0 deletions Artifacts/08_24_2024_13_22_11/data_ingestion/ingested/train.csv

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Abnormal_URL:
drift_status: false
p_value: 0.09511048419639119
DNSRecord:
drift_status: false
p_value: 0.9328006214323754
Domain_registeration_length:
drift_status: false
p_value: 0.998821814236978
Favicon:
drift_status: false
p_value: 1.0
Google_Index:
drift_status: false
p_value: 0.8079952786138995
HTTPS_token:
drift_status: false
p_value: 0.9413205455808915
Iframe:
drift_status: false
p_value: 1.0
Links_in_tags:
drift_status: false
p_value: 0.8427303427983684
Links_pointing_to_page:
drift_status: false
p_value: 1.0
Page_Rank:
drift_status: false
p_value: 1.0
Prefix_Suffix:
drift_status: false
p_value: 1.0
Redirect:
drift_status: false
p_value: 0.9970105474352128
Request_URL:
drift_status: false
p_value: 0.9964705532516113
Result:
drift_status: false
p_value: 0.37182939454122055
RightClick:
drift_status: false
p_value: 1.0
SFH:
drift_status: false
p_value: 0.9999760319468036
SSLfinal_State:
drift_status: false
p_value: 0.8807137057443575
Shortining_Service:
drift_status: false
p_value: 0.45991477918984003
Statistical_report:
drift_status: false
p_value: 1.0
Submitting_to_email:
drift_status: false
p_value: 1.0
URL_Length:
drift_status: false
p_value: 0.9999998099738984
URL_of_Anchor:
drift_status: false
p_value: 0.41112810853494
age_of_domain:
drift_status: false
p_value: 0.9999999999997877
double_slash_redirecting:
drift_status: false
p_value: 0.8079952786138995
having_At_Symbol:
drift_status: false
p_value: 0.9925611176019148
having_IP_Address:
drift_status: false
p_value: 1.0
having_Sub_Domain:
drift_status: false
p_value: 0.9964705532516113
on_mouseover:
drift_status: false
p_value: 0.9985597993583677
popUpWidnow:
drift_status: false
p_value: 1.0
port:
drift_status: false
p_value: 0.9999999489728584
web_traffic:
drift_status: false
p_value: 0.4527621454370569
Binary file not shown.
Binary file not shown.
74 changes: 71 additions & 3 deletions networksecurity/components/model_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,78 @@
from networksecurity.utils.ml_utils.model.estimator import NetworkModel
from networksecurity.utils.main_utils.utils import save_object,load_object
from networksecurity.utils.main_utils.utils import load_numpy_array_data

from networksecurity.utils.ml_utils.metric.classification_metric import get_classification_score



class ModelTrainer:
def __init__(self):
pass

def __init__(self,model_trainer_config:ModelTrainerConfig,
data_transformation_artifact:DataTransformationArtifact):
try:
self.model_trainer_config=model_trainer_config
self.data_transformation_artifact=data_transformation_artifact
except Exception as e:
raise NetworkSecurityException(e,sys)

def perform_hyper_parameter_tunig(self):
pass


def train_model(self,x_train,y_train):
try:
xgb_clf = XGBClassifier()
xgb_clf.fit(x_train,y_train)
return xgb_clf
except Exception as e:
raise e

def initiate_model_trainer(self)->ModelTrainerArtifact:
try:
train_file_path = self.data_transformation_artifact.transformed_train_file_path
test_file_path = self.data_transformation_artifact.transformed_test_file_path

#loading training array and testing array
train_arr = load_numpy_array_data(train_file_path)
test_arr = load_numpy_array_data(test_file_path)

x_train, y_train, x_test, y_test = (
train_arr[:, :-1],
train_arr[:, -1],
test_arr[:, :-1],
test_arr[:, -1],
)

model = self.train_model(x_train, y_train)
y_train_pred = model.predict(x_train)
classification_train_metric = get_classification_score(y_true=y_train, y_pred=y_train_pred)

if classification_train_metric.f1_score<=self.model_trainer_config.expected_accuracy:
raise Exception("Trained model is not good to provide expected accuracy")

y_test_pred = model.predict(x_test)
classification_test_metric = get_classification_score(y_true=y_test, y_pred=y_test_pred)


#Overfitting and Underfitting
diff = abs(classification_train_metric.f1_score-classification_test_metric.f1_score)

if diff>self.model_trainer_config.overfitting_underfitting_threshold:
raise Exception("Model is not good try to do more experimentation.")

preprocessor = load_object(file_path=self.data_transformation_artifact.transformed_object_file_path)

model_dir_path = os.path.dirname(self.model_trainer_config.trained_model_file_path)
os.makedirs(model_dir_path,exist_ok=True)
Network_Model = NetworkModel(preprocessor=preprocessor,model=model)
save_object(self.model_trainer_config.trained_model_file_path, obj=Network_Model)

#model trainer artifact

model_trainer_artifact = ModelTrainerArtifact(trained_model_file_path=self.model_trainer_config.trained_model_file_path,
train_metric_artifact=classification_train_metric,
test_metric_artifact=classification_test_metric)
logging.info(f"Model trainer artifact: {model_trainer_artifact}")
return model_trainer_artifact
except Exception as e:
raise NetworkSecurityException(e,sys)
Binary file not shown.
Binary file modified networksecurity/entity/__pycache__/artifact_entity.cpython-310.pyc
Binary file not shown.
Binary file modified networksecurity/entity/__pycache__/config_entity.cpython-310.pyc
Binary file not shown.
8 changes: 5 additions & 3 deletions networksecurity/entity/artifact_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class DataTransformationArtifact:
transformed_test_file_path: str

@dataclass
class ClassificationMetricArtifact:
f1_score: float
precision_score: float
recall_score: float
@dataclass
class ModelTrainerArtifact:
trained_model_file_path: str
train_metric_artifact: ClassificationMetricArtifact
Expand All @@ -35,6 +40,3 @@ class ModelEvaluationArtifact:
class ModelPusherArtifact:
pass

@dataclass
class ClassificationMetricArtifact:
pass
Binary file not shown.

0 comments on commit 90ce3b6

Please sign in to comment.