File size: 3,310 Bytes
73bd02c
 
 
 
 
 
8d9c11c
73bd02c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9086fb
73bd02c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab86df6
73bd02c
 
 
 
 
 
 
 
 
 
 
 
 
7f29fdb
13aad8e
7f29fdb
13aad8e
7f29fdb
 
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
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.pipeline import Pipeline
import streamlit as st

# Veri okuma
df = pd.read_excel('iot predictive analysis.xlsx')

# Sütun isimlerindeki boşlukları temizleme
df.columns = df.columns.str.strip()

# Değişkenlerin açıklaması
columns_dict = {
    'footfall': 'Belirli bir süre boyunca bir alandan geçen kişi sayısı.',
    'atemp': 'Sensörün bulunduğu alanın dış ortam sıcaklığı.',
    'selfLR': 'Bir cihazın kendi içindeki yük direnci.',
    'ClinLR': 'Belirli bir klinik ortamda kullanılan yük direnci.',
    'DoleLR': 'Belirli bir alandaki yük direncidir.',
    'PID': 'Orantısal, integral ve türev kontrol sistemi değeri.',
    'outpressure': 'Cihazın dış ortam basıncı.',
    'inpressure': 'Cihazın iç ortam basıncı.',
    'temp': 'Genel ortam sıcaklığı.',
    'fail': 'Cihazın arıza durumu.'
}

# Veri setini özellikler ve hedef olarak ayırma
y = df.fail
X = df.drop(['fail'], axis=1)

# Eğitim ve test kümelerine ayırma
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Ön işleme adımları
preprocess = ColumnTransformer(transformers=[
    ('num', StandardScaler(), ['footfall', 'atemp', 'selfLR', 'ClinLR', 'DoleLR', 'PID', 'outpressure', 'inpressure', 'temp'])
])

# Model tanımlama
model = LinearRegression()
pipe = Pipeline(steps=[('preprocessor', preprocess), ('model', model)])

# Modeli eğitme
pipe.fit(X_train, y_train)

# Tahmin ve değerlendirme
y_pred = pipe.predict(X_test)
print("Root Mean Squared Error: ", mean_squared_error(y_test, y_pred) ** 0.5)
print("R^2 Score: ", r2_score(y_test, y_pred))

# Streamlit uygulaması
def fail(footfall, atemp, selfLR, ClinLR, DoleLR, PID, outpressure, inpressure, temp):
    input_data = pd.DataFrame({
        'footfall': [footfall],
        'atemp': [atemp],
        'selfLR': [selfLR],
        'ClinLR': [ClinLR],
        'DoleLR': [DoleLR],
        'PID': [PID],
        'outpressure': [outpressure],
        'inpressure': [inpressure],
        'temp': [temp]
    })
    prediction = pipe.predict(input_data)[0]
    return prediction

st.title("İot Analizi :information: @YED")
st.write("Lütfen Sensör Verilerini Giriniz.")
footfall = st.number_input("Footfall", 0, 10000)
atemp = st.number_input("Atemp", 0, 100)
selfLR = st.number_input("SelfLR", 0, 100)
ClinLR = st.number_input("ClinLR", 0, 100)
DoleLR = st.number_input("DoleLR", 0, 100)
PID = st.number_input("PID", 0, 100)
outpressure = st.number_input("Outpressure", 0, 100)
inpressure = st.number_input("Inpressure", 0, 100)
temp = st.number_input("Temp", 0, 100)

if st.button("Predict"):
    pred = fail(footfall, atemp, selfLR, ClinLR, DoleLR, PID, outpressure, inpressure, temp)
    if pred>=1:
        result ="1 ; Sensör arızalı lütfen kontrol ediniz"
    else:
        result ="0 ; Sensör çalışıyor işe devam edebilirsiniz"
    
    st.write("Sensör Durumu  ", result)