File size: 1,810 Bytes
34ffff8
 
 
 
 
 
 
 
 
 
 
 
db00fdf
 
 
8bedea7
db00fdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a4c793
db00fdf
 
 
 
 
 
 
 
 
 
 
 
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
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn import preprocessing
import seaborn as sns
from sklearn.preprocessing import LabelEncoder
import streamlit as st 

st.title("Rouge Component Model")
#Reading Dataset
df = pd.read_csv('identify_rogue_50K_ALL.csv')
print("Dataset Size:",df.shape)
st.sidebar.header('Enter the Components Details here')
# Dropping the SRU serial number
df.drop(['SRU serial number','Date of Manufacture','Last Maintenance Date','date of last failure'], axis = 1, inplace=True)

def label_encoder(df):
  le = LabelEncoder()
  cat = df.select_dtypes(include='O').keys()
  categ = list(cat)
  df[categ] = df[categ].apply(le.fit_transform)
  return df

def preprocess_dataset(X):  
  x = X.values #returns a numpy array
  min_max_scaler = preprocessing.MinMaxScaler()
  x_scaled = min_max_scaler.fit_transform(x)
  X_df = pd.DataFrame(x_scaled)
  return X_df

def prediction(df):
  X = df.loc[:,df.columns!= "Rogue LRU/SRU (Target)"]
  y = df["Rogue LRU/SRU (Target)"]
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=42)
  print(X_train.shape)
  print(X_test.shape)
  X_test_encoded = label_encoder(X_test)
  X_test_df = preprocess_dataset(X_test_encoded)
  x_model = loaded_model = tf.keras.models.load_model('my_model')
  y_pred = x_model.predict(X_test_df)
  predicition = []
  for i in list(y_pred):
    if i[0]<=0.8:
      predicition.append(0)
    else:
      predicition.append(1)
  X_test['Actual_time_to_repair'] = y_test
  X_test['Predicted_time_to_repair'] = predicition
  # X_test.to_csv(r'/content/drive/MyDrive/Colab Notebooks/HAL/rogue_test_data.csv')
  print(X_test.head())
prediction(df)