saritha5 commited on
Commit
db00fdf
·
1 Parent(s): 0c51930

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py CHANGED
@@ -10,3 +10,45 @@ from sklearn.preprocessing import LabelEncoder
10
  import streamlit as st
11
 
12
  st.title("Rouge Component Model")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  import streamlit as st
11
 
12
  st.title("Rouge Component Model")
13
+ #Reading Dataset
14
+ df = pd.read_csv('identify_rogue_50K_ALL.csv')
15
+ print("Dataset Size:",df.shape)
16
+
17
+ # Dropping the SRU serial number
18
+ df.drop(['SRU serial number','Date of Manufacture','Last Maintenance Date','date of last failure'], axis = 1, inplace=True)
19
+
20
+ def label_encoder(df):
21
+ le = LabelEncoder()
22
+ cat = df.select_dtypes(include='O').keys()
23
+ categ = list(cat)
24
+ df[categ] = df[categ].apply(le.fit_transform)
25
+ return df
26
+
27
+ def preprocess_dataset(X):
28
+ x = X.values #returns a numpy array
29
+ min_max_scaler = preprocessing.MinMaxScaler()
30
+ x_scaled = min_max_scaler.fit_transform(x)
31
+ X_df = pd.DataFrame(x_scaled)
32
+ return X_df
33
+
34
+ def prediction(df):
35
+ X = df.loc[:,df.columns!= "Rogue LRU/SRU (Target)"]
36
+ y = df["Rogue LRU/SRU (Target)"]
37
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=42)
38
+ print(X_train.shape)
39
+ print(X_test.shape)
40
+ X_test_encoded = label_encoder(X_test)
41
+ X_test_df = preprocess_dataset(X_test_encoded)
42
+ x_model = loaded_model = tf.keras.models.load_model(r'/content/drive/MyDrive/Colab Notebooks/HAL/saved_model/my_model')
43
+ y_pred = x_model.predict(X_test_df)
44
+ predicition = []
45
+ for i in list(y_pred):
46
+ if i[0]<=0.8:
47
+ predicition.append(0)
48
+ else:
49
+ predicition.append(1)
50
+ X_test['Actual_time_to_repair'] = y_test
51
+ X_test['Predicted_time_to_repair'] = predicition
52
+ # X_test.to_csv(r'/content/drive/MyDrive/Colab Notebooks/HAL/rogue_test_data.csv')
53
+ print(X_test.head())
54
+ prediction(df)