File size: 3,838 Bytes
cc1c4e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d84cbc8
cc1c4e2
 
 
 
 
9517217
2f4060f
366a1f5
 
cc1c4e2
 
 
d84cbc8
cc1c4e2
 
 
 
 
 
 
 
2f4060f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b6a1c7
2f4060f
 
 
 
366a1f5
2f4060f
aa6d54e
d84cbc8
cc1c4e2
2f4060f
cc1c4e2
 
2f4060f
 
 
cc1c4e2
 
2f4060f
cc1c4e2
 
 
 
848d2fb
aa6d54e
848d2fb
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

# import required libraries

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

from datetime import datetime
from datetime import timedelta
from sklearn.model_selection import RandomizedSearchCV, GridSearchCV, train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import r2_score
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import StandardScaler
import streamlit as st 
import warnings
warnings.filterwarnings('ignore')



st.title("Prediction of Maximum Number of Repairs")
st.sidebar.header('Enter the Components Details here')
st.write("""This model helps to know the probable maximum number of times a component can be repaired.
After which, we can straight away replace it with a new component""")
import pandas as pd
import numpy as np
import pickle

# load the saved model using pickle
with open('max_repair_model.pkl', 'rb') as file:
    model = pickle.load(file)
    
# Load the saved manufacturer label encoder object using pickle
with open('manufacturer_le.pkl', 'rb') as file1:
    le = pickle.load(file1)
    
# DATA from user
def user_report():
  manufacturer = st.sidebar.selectbox("Manufacturer",
        ("JKL Company", "GHI Company","DEF Company","ABC Company","XYZ Company" ))
  if manufacturer=='JKL Company':
      manufacturer=3
  elif manufacturer=="GHI Company":
      manufacturer=2
  elif manufacturer=="DEF Company":
      manufacturer=1
  elif manufacturer=="ABC Company":
      manufacturer =0
  else:
      manufacturer=4
  component_age = st.sidebar.slider('Component Age (in hours)', 100,250, 300 )
  total_operating_hours = st.sidebar.slider('Total Operating Hours)', 400,1500, 500 )
  operating_temperature = st.sidebar.slider('Operating Temperature', 70,80, 75 )  
  humidity = st.sidebar.slider('Humidity', 50,70, 55 ) 
  Vibration_Level = st.sidebar.slider('Vibration Level', 2,4, 2 )
  Pressure = st.sidebar.slider('Pressure', 28,32, 30 ) 
  Power_Input_Voltage= st.sidebar.slider('Power Input Voltage (V)',105,120,115)
  previous_number_of_repairs = st.sidebar.number_input('Enter the Previous Number of Repairs Undergone  0 to 5 )',min_value=0,max_value=5,step=1)  
  load_factor = st.sidebar.slider('Load Factor',3,10,4)
  engine_speed=st.sidebar.slider('Engine Speed',7000,8000,7800)
  Oil_Temperature=st.sidebar.slider('Oil Temperature',170,185,172)  
    
  
  user_report_data = {
       'Manufacturer': manufacturer, 
       'Component_Age': component_age, 
       'Total_Operating_Hours': total_operating_hours, 
       'Operating_Temperature': operating_temperature, 
       'Humidity': humidity, 
       'Vibration_Level': Vibration_Level, 
       'Pressure': Pressure, 
       'Power_Input_Voltage': Power_Input_Voltage, 
       'Previous_number_of_repairs': previous_number_of_repairs, 
       'Load_Factor': load_factor, 
       'Engine_Speed': engine_speed, 
       'Oil_Temperature':Oil_Temperature      
  }
  report_data = pd.DataFrame(user_report_data, index=[0])
  
  return report_data    
    
#Customer Data
user_data = user_report()
st.subheader("Component Details")
st.write(user_data)


# define the prediction function
def predict_max_number_of_repairs(user_data):
    
    # encode the manufacturer using the loaded LabelEncoder object
    #manufacturer_encoded = le.transform([manufacturer])[0]
    
    
    
    # make the prediction using the loaded model and input data
    predicted_max_number_of_repairs = model.predict(user_data)
    
    # return the predicted max number of repairs as output
    return np.round(predicted_max_number_of_repairs[0])
# Function calling
y_pred = int(predict_max_number_of_repairs(user_data))
st.write("Click here to see the Predictions")
if st.button("Predict"):
    st.subheader(f"Maximun Number of Repairs is {y_pred} ")