import pandas as pd import streamlit as st import joblib from sklearn.preprocessing import StandardScaler, OneHotEncoder from sklearn.model_selection import train_test_split from sklearn.compose import ColumnTransformer # Veriyi yükleme ve sütun isimlerini güncelleme df = pd.read_csv('MiningProcess_Flotation_Plant_Database.csv') df.columns = df.columns.str.replace(r'[\s\.]', '_', regex=True) df.columns = df.columns.str.replace(r'%_Silica_Feed', 'Silica_Feed', regex=True) df.columns = df.columns.str.replace(r'%_Silica_Concentrate', 'Silica_Concentrate', regex=True) columns_to_convert = df.columns.difference(['date']) df[columns_to_convert] = df[columns_to_convert].replace(',', '.', regex=True).astype(float) # Bağımlı ve bağımsız değişkenlerin seçimi x = df.drop(['date','%_Iron_Feed','%_Iron_Concentrate', 'Silica_Concentrate'], axis=1) y = df[['Silica_Concentrate']] # Eğitim ve test verilerini ayırma x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.20, random_state=42) # Ön işleme (StandardScaler ve OneHotEncoder) preprocessor = ColumnTransformer( transformers=[ ('num', StandardScaler(), ['Silica_Feed','Starch_Flow','Amina_Flow','Ore_Pulp_Flow','Ore_Pulp_pH','Ore_Pulp_Density', 'Flotation_Column_01_Air_Flow','Flotation_Column_02_Air_Flow','Flotation_Column_03_Air_Flow', 'Flotation_Column_04_Air_Flow','Flotation_Column_05_Air_Flow','Flotation_Column_06_Air_Flow', 'Flotation_Column_07_Air_Flow','Flotation_Column_01_Level','Flotation_Column_02_Level', 'Flotation_Column_03_Level','Flotation_Column_04_Level','Flotation_Column_05_Level', 'Flotation_Column_06_Level','Flotation_Column_07_Level']) ] ) def silica_pred(Silica_Feed,Starch_Flow,Amina_Flow,Ore_Pulp_Flow,Ore_Pulp_pH,Ore_Pulp_Density,Flotation_Column_01_Air_Flow, Flotation_Column_02_Air_Flow,Flotation_Column_03_Air_Flow,Flotation_Column_04_Air_Flow,Flotation_Column_05_Air_Flow, Flotation_Column_06_Air_Flow,Flotation_Column_07_Air_Flow,Flotation_Column_01_Level,Flotation_Column_02_Level, Flotation_Column_03_Level,Flotation_Column_04_Level,Flotation_Column_05_Level,Flotation_Column_06_Level, Flotation_Column_07_Level): input_data = pd.DataFrame({ 'Silica_Feed': [Silica_Feed], 'Starch_Flow': [Starch_Flow], 'Amina_Flow': [Amina_Flow], 'Ore_Pulp_Flow': [Ore_Pulp_Flow], 'Ore_Pulp_pH': [Ore_Pulp_pH], 'Ore_Pulp_Density': [Ore_Pulp_Density], 'Flotation_Column_01_Air_Flow': [Flotation_Column_01_Air_Flow], 'Flotation_Column_02_Air_Flow': [Flotation_Column_02_Air_Flow], 'Flotation_Column_03_Air_Flow': [Flotation_Column_03_Air_Flow], 'Flotation_Column_04_Air_Flow': [Flotation_Column_04_Air_Flow], 'Flotation_Column_05_Air_Flow': [Flotation_Column_05_Air_Flow], 'Flotation_Column_06_Air_Flow': [Flotation_Column_06_Air_Flow], 'Flotation_Column_07_Air_Flow': [Flotation_Column_07_Air_Flow], 'Flotation_Column_01_Level': [Flotation_Column_01_Level], 'Flotation_Column_02_Level': [Flotation_Column_02_Level], 'Flotation_Column_03_Level': [Flotation_Column_03_Level], 'Flotation_Column_04_Level': [Flotation_Column_04_Level], 'Flotation_Column_05_Level': [Flotation_Column_05_Level], 'Flotation_Column_06_Level': [Flotation_Column_06_Level], 'Flotation_Column_07_Level': [Flotation_Column_07_Level] }) input_data_transformed = preprocessor.fit_transform(input_data) model = joblib.load('Silisyum.pkl') prediction = model.predict(input_data_transformed) return float(prediction[0]) min_Silica_Feed = x['Silica_Feed'].min() max_Silica_Feed = x['Silica_Feed'].max() min_Starch_Flow = x['Starch_Flow'].min() max_Starch_Flow = x['Starch_Flow'].max() min_Amina_Flow = x['Amina_Flow'].min() max_Amina_Flow = x['Amina_Flow'].max() min_Ore_Pulp_Flow = x['Ore_Pulp_Flow'].min() max_Ore_Pulp_Flow = x['Ore_Pulp_Flow'].max() min_Ore_Pulp_pH = x['Ore_Pulp_pH'].min() max_Ore_Pulp_pH = x['Ore_Pulp_pH'].max() min_Ore_Pulp_Density = x['Ore_Pulp_Density'].min() max_Ore_Pulp_Density = x['Ore_Pulp_Density'].max() min_Flotation_Column_01_Air_Flow = x['Flotation_Column_01_Air_Flow'].min() max_Flotation_Column_01_Air_Flow = x['Flotation_Column_01_Air_Flow'].max() min_Flotation_Column_02_Air_Flow = x['Flotation_Column_02_Air_Flow'].min() max_Flotation_Column_02_Air_Flow = x['Flotation_Column_02_Air_Flow'].max() min_Flotation_Column_03_Air_Flow = x['Flotation_Column_03_Air_Flow'].min() max_Flotation_Column_03_Air_Flow = x['Flotation_Column_03_Air_Flow'].max() min_Flotation_Column_04_Air_Flow = x['Flotation_Column_04_Air_Flow'].min() max_Flotation_Column_04_Air_Flow = x['Flotation_Column_04_Air_Flow'].max() min_Flotation_Column_05_Air_Flow = x['Flotation_Column_05_Air_Flow'].min() max_Flotation_Column_05_Air_Flow = x['Flotation_Column_05_Air_Flow'].max() min_Flotation_Column_06_Air_Flow = x['Flotation_Column_06_Air_Flow'].min() max_Flotation_Column_06_Air_Flow = x['Flotation_Column_06_Air_Flow'].max() min_Flotation_Column_07_Air_Flow = x['Flotation_Column_07_Air_Flow'].min() max_Flotation_Column_07_Air_Flow = x['Flotation_Column_07_Air_Flow'].max() min_Flotation_Column_01_Level = x['Flotation_Column_01_Level'].min() max_Flotation_Column_01_Level = x['Flotation_Column_01_Level'].max() min_Flotation_Column_02_Level = x['Flotation_Column_02_Level'].min() max_Flotation_Column_02_Level = x['Flotation_Column_02_Level'].max() min_Flotation_Column_03_Level = x['Flotation_Column_03_Level'].min() max_Flotation_Column_03_Level = x['Flotation_Column_03_Level'].max() min_Flotation_Column_04_Level = x['Flotation_Column_04_Level'].min() max_Flotation_Column_04_Level = x['Flotation_Column_04_Level'].max() min_Flotation_Column_05_Level = x['Flotation_Column_05_Level'].min() max_Flotation_Column_05_Level = x['Flotation_Column_05_Level'].max() min_Flotation_Column_06_Level = x['Flotation_Column_06_Level'].min() max_Flotation_Column_06_Level = x['Flotation_Column_06_Level'].max() min_Flotation_Column_07_Level = x['Flotation_Column_07_Level'].min() max_Flotation_Column_07_Level = x['Flotation_Column_07_Level'].max() st.title("Maden Veri seti ile Silica saflık Regresyon Modeli") st.write("Veri Gir") Silica_Feed = st.slider('Silica_Feed', float(min_Silica_Feed), float(max_Silica_Feed)) Starch_Flow = st.slider('Starch_Flow', float(min_Starch_Flow), float(max_Starch_Flow)) Amina_Flow = st.slider('Amina_Flow', float(min_Amina_Flow), float(max_Amina_Flow)) Ore_Pulp_Flow = st.slider('Ore_Pulp_Flow', float(min_Ore_Pulp_Flow), float(max_Ore_Pulp_Flow)) Ore_Pulp_pH = st.slider('Ore_Pulp_pH', float(min_Ore_Pulp_pH), float(max_Ore_Pulp_pH)) Ore_Pulp_Density = st.slider('Ore_Pulp_Density', float(min_Ore_Pulp_Density), float(max_Ore_Pulp_Density)) Flotation_Column_01_Air_Flow = st.slider('Flotation_Column_01_Air_Flow', float(min_Flotation_Column_01_Air_Flow), float(max_Flotation_Column_01_Air_Flow)) Flotation_Column_02_Air_Flow = st.slider('Flotation_Column_02_Air_Flow', float(min_Flotation_Column_02_Air_Flow), float(max_Flotation_Column_02_Air_Flow)) Flotation_Column_03_Air_Flow = st.slider('Flotation_Column_03_Air_Flow', float(min_Flotation_Column_03_Air_Flow), float(max_Flotation_Column_03_Air_Flow)) Flotation_Column_04_Air_Flow = st.slider('Flotation_Column_04_Air_Flow', float(min_Flotation_Column_04_Air_Flow), float(max_Flotation_Column_04_Air_Flow)) Flotation_Column_05_Air_Flow = st.slider('Flotation_Column_05_Air_Flow', float(min_Flotation_Column_05_Air_Flow), float(max_Flotation_Column_05_Air_Flow)) Flotation_Column_06_Air_Flow = st.slider('Flotation_Column_06_Air_Flow', float(min_Flotation_Column_06_Air_Flow), float(max_Flotation_Column_06_Air_Flow)) Flotation_Column_07_Air_Flow = st.slider('Flotation_Column_07_Air_Flow', float(min_Flotation_Column_07_Air_Flow), float(max_Flotation_Column_07_Air_Flow)) Flotation_Column_01_Level = st.slider('Flotation_Column_01_Level', float(min_Flotation_Column_01_Level), float(max_Flotation_Column_01_Level)) Flotation_Column_02_Level = st.slider('Flotation_Column_02_Level', float(min_Flotation_Column_02_Level), float(max_Flotation_Column_02_Level)) Flotation_Column_03_Level = st.slider('Flotation_Column_03_Level', float(min_Flotation_Column_03_Level), float(max_Flotation_Column_03_Level)) Flotation_Column_04_Level = st.slider('Flotation_Column_04_Level', float(min_Flotation_Column_04_Level), float(max_Flotation_Column_04_Level)) Flotation_Column_05_Level = st.slider('Flotation_Column_05_Level', float(min_Flotation_Column_05_Level), float(max_Flotation_Column_05_Level)) Flotation_Column_06_Level = st.slider('Flotation_Column_06_Level', float(min_Flotation_Column_06_Level), float(max_Flotation_Column_06_Level)) Flotation_Column_07_Level = st.slider('Flotation_Column_07_Level', float(min_Flotation_Column_07_Level), float(max_Flotation_Column_07_Level)) # Predict button if st.button('Silica Saflığını Tahmin Et'): prediction = silica_pred(Silica_Feed, Starch_Flow, Amina_Flow, Ore_Pulp_Flow, Ore_Pulp_pH, Ore_Pulp_Density, Flotation_Column_01_Air_Flow, Flotation_Column_02_Air_Flow, Flotation_Column_03_Air_Flow, Flotation_Column_04_Air_Flow, Flotation_Column_05_Air_Flow, Flotation_Column_06_Air_Flow, Flotation_Column_07_Air_Flow, Flotation_Column_01_Level, Flotation_Column_02_Level, Flotation_Column_03_Level, Flotation_Column_04_Level, Flotation_Column_05_Level, Flotation_Column_06_Level, Flotation_Column_07_Level) st.write(f'Tahmin edilen Silica Saflığı: {prediction:.2f}')