saritha5's picture
Update app.py
3a4c793
raw
history blame
1.76 kB
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)
# 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)