Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +88 -0
- iot predictive analysis.xlsx +0 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import warnings
|
| 5 |
+
warnings.filterwarnings('ignore')
|
| 6 |
+
from sklearn.model_selection import train_test_split
|
| 7 |
+
from sklearn.linearRegression import LinearRegression
|
| 8 |
+
from sklearn.metrics import mean_squared_error, r2_score
|
| 9 |
+
from sklearn.compose import ColumnTransformer
|
| 10 |
+
from sklearn.preprocessing import OneHotEncoder, StandardScaler
|
| 11 |
+
from sklearn.pipeline import Pipeline
|
| 12 |
+
import streamlit as st
|
| 13 |
+
|
| 14 |
+
# Veri okuma
|
| 15 |
+
df = pd.read_excel('iot predictive analysis.xlsx')
|
| 16 |
+
|
| 17 |
+
# Sütun isimlerindeki boşlukları temizleme
|
| 18 |
+
df.columns = df.columns.str.strip()
|
| 19 |
+
|
| 20 |
+
# Değişkenlerin açıklaması
|
| 21 |
+
columns_dict = {
|
| 22 |
+
'footfall': 'Belirli bir süre boyunca bir alandan geçen kişi sayısı.',
|
| 23 |
+
'atemp': 'Sensörün bulunduğu alanın dış ortam sıcaklığı.',
|
| 24 |
+
'selfLR': 'Bir cihazın kendi içindeki yük direnci.',
|
| 25 |
+
'ClinLR': 'Belirli bir klinik ortamda kullanılan yük direnci.',
|
| 26 |
+
'DoleLR': 'Belirli bir alandaki yük direnci.',
|
| 27 |
+
'PID': 'Orantısal, integral ve türev kontrol sistemi değeri.',
|
| 28 |
+
'outpressure': 'Cihazın dış ortam basıncı.',
|
| 29 |
+
'inpressure': 'Cihazın iç ortam basıncı.',
|
| 30 |
+
'temp': 'Genel ortam sıcaklığı.',
|
| 31 |
+
'fail': 'Cihazın arıza durumu.'
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
# Veri setini özellikler ve hedef olarak ayırma
|
| 35 |
+
y = df.fail
|
| 36 |
+
X = df.drop(['fail'], axis=1)
|
| 37 |
+
|
| 38 |
+
# Eğitim ve test kümelerine ayırma
|
| 39 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 40 |
+
|
| 41 |
+
# Ön işleme adımları
|
| 42 |
+
preprocess = ColumnTransformer(transformers=[
|
| 43 |
+
('num', StandardScaler(), ['footfall', 'atemp', 'selfLR', 'ClinLR', 'DoleLR', 'PID', 'outpressure', 'inpressure', 'temp'])
|
| 44 |
+
])
|
| 45 |
+
|
| 46 |
+
# Model tanımlama
|
| 47 |
+
model = LinearRegression()
|
| 48 |
+
pipe = Pipeline(steps=[('preprocessor', preprocess), ('model', model)])
|
| 49 |
+
|
| 50 |
+
# Modeli eğitme
|
| 51 |
+
pipe.fit(X_train, y_train)
|
| 52 |
+
|
| 53 |
+
# Tahmin ve değerlendirme
|
| 54 |
+
y_pred = pipe.predict(X_test)
|
| 55 |
+
print("Root Mean Squared Error: ", mean_squared_error(y_test, y_pred) ** 0.5)
|
| 56 |
+
print("R^2 Score: ", r2_score(y_test, y_pred))
|
| 57 |
+
|
| 58 |
+
# Streamlit uygulaması
|
| 59 |
+
def fail(footfall, atemp, selfLR, ClinLR, DoleLR, PID, outpressure, inpressure, temp):
|
| 60 |
+
input_data = pd.DataFrame({
|
| 61 |
+
'footfall': [footfall],
|
| 62 |
+
'atemp': [atemp],
|
| 63 |
+
'selfLR': [selfLR],
|
| 64 |
+
'ClinLR': [ClinLR],
|
| 65 |
+
'DoleLR': [DoleLR],
|
| 66 |
+
'PID': [PID],
|
| 67 |
+
'outpressure': [outpressure],
|
| 68 |
+
'inpressure': [inpressure],
|
| 69 |
+
'temp': [temp]
|
| 70 |
+
})
|
| 71 |
+
prediction = pipe.predict(input_data)[0]
|
| 72 |
+
return prediction
|
| 73 |
+
|
| 74 |
+
st.title("İot Analizi :information: @dryed")
|
| 75 |
+
st.write("Lütfen Sensör Verilerini Giriniz.")
|
| 76 |
+
footfall = st.number_input("Footfall", 0, 10000)
|
| 77 |
+
atemp = st.number_input("Atemp", 0, 100)
|
| 78 |
+
selfLR = st.number_input("SelfLR", 0, 100)
|
| 79 |
+
ClinLR = st.number_input("ClinLR", 0, 100)
|
| 80 |
+
DoleLR = st.number_input("DoleLR", 0, 100)
|
| 81 |
+
PID = st.number_input("PID", 0, 100)
|
| 82 |
+
outpressure = st.number_input("Outpressure", 0, 100)
|
| 83 |
+
inpressure = st.number_input("Inpressure", 0, 100)
|
| 84 |
+
temp = st.number_input("Temp", 0, 100)
|
| 85 |
+
|
| 86 |
+
if st.button("Predict"):
|
| 87 |
+
pred = fail(footfall, atemp, selfLR, ClinLR, DoleLR, PID, outpressure, inpressure, temp)
|
| 88 |
+
st.write("Predicted fail :information: $", pred)
|
iot predictive analysis.xlsx
ADDED
|
Binary file (54.9 kB). View file
|
|
|
requirements.txt
ADDED
|
Binary file (190 Bytes). View file
|
|
|