-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_functions_3.py
48 lines (38 loc) · 1.53 KB
/
web_functions_3.py
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
"""This module contains necessary function needed"""
# Import necessary modules
import numpy as np
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
import streamlit as st
@st.cache_data()
def load_data():
"""This function returns the preprocessed data"""
# Load the Diabetes dataset into DataFrame.
df = pd.read_csv('cloud_DB.csv')
# Perform feature and target split
X = df[["Data_Sensitivity_Classification", "Logging_and_Monitoring", "Cross_Region_Access", "Segmentation_of_Duties", "Shared_Responsibility_Model", "Access_Control_Propagation", "API_Access_Control", "Cloud_Workload_Identity", "Audit_Trails"]]
y = df['Cloud_Score']
return df, X, y
@st.cache_data()
def train_model(X, y):
"""This function trains the model and return the model and model score"""
# Create the model
model = DecisionTreeClassifier(
ccp_alpha=0.0, class_weight=None, criterion='entropy',
max_depth=4, max_features=None, max_leaf_nodes=None,
min_impurity_decrease=0.0, min_samples_leaf=1,
min_samples_split=2, min_weight_fraction_leaf=0.0,
random_state=42, splitter='best'
)
# Fit the data on model
model.fit(X, y)
# Get the model score
score = model.score(X, y)
# Return the values
return model, score
def predict(X, y, features):
# Get model and model score
model, score = train_model(X, y)
# Predict the value
prediction = model.predict(np.array(features).reshape(1, -1))
return prediction, score