Spaces:
Sleeping
Sleeping
File size: 10,060 Bytes
54203a1 |
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
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}') |