Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,60 +1,39 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
-
import plotly.
|
| 5 |
-
from sklearn.model_selection import train_test_split
|
| 6 |
from sklearn.ensemble import RandomForestRegressor
|
|
|
|
| 7 |
from sklearn.metrics import mean_squared_error
|
| 8 |
-
import matplotlib.pyplot as plt
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
st.title('داشبورد
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
st.
|
| 15 |
-
uploaded_file = st.sidebar.file_uploader("فایل CSV، Excel، PDF یا TIFF خود را آپلود کنید", type=["csv", "xlsx", "pdf", "tiff"])
|
| 16 |
-
|
| 17 |
-
# پردازش دادهها
|
| 18 |
if uploaded_file is not None:
|
|
|
|
| 19 |
df = pd.read_csv(uploaded_file)
|
| 20 |
-
st.write(
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
st.plotly_chart(fig)
|
| 31 |
-
|
| 32 |
-
# نمایش نمودار هیستوگرام سه بعدی
|
| 33 |
-
hist_data = [go.Histogram3d(
|
| 34 |
-
x=df['هفته'], y=df['رشد'], z=df['ارتفاع'],
|
| 35 |
-
colorscale='Viridis'
|
| 36 |
-
)]
|
| 37 |
-
hist_layout = go.Layout(title='هیستوگرام سه بعدی ارتفاع', width=700, height=700)
|
| 38 |
-
st.plotly_chart(go.Figure(data=hist_data, layout=hist_layout))
|
| 39 |
-
|
| 40 |
-
# تجزیه و تحلیل یادگیری ماشین
|
| 41 |
-
X = df.drop(columns=['Yield'])
|
| 42 |
-
y = df['Yield']
|
| 43 |
-
|
| 44 |
-
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 45 |
-
|
| 46 |
-
model = RandomForestRegressor(n_estimators=100, random_state=42)
|
| 47 |
-
model.fit(X_train, y_train)
|
| 48 |
-
|
| 49 |
-
y_pred = model.predict(X_test)
|
| 50 |
-
mse = mean_squared_error(y_test, y_pred)
|
| 51 |
-
st.write(f"خطای میانگین مربعات: {mse}")
|
| 52 |
-
|
| 53 |
-
# نمایش توصیههای NPK
|
| 54 |
-
st.write("توصیههای NPK برای سطح خاک:")
|
| 55 |
-
npk_recommendations = model.feature_importances_
|
| 56 |
-
st.write(f"N: {npk_recommendations[0]:.2f}, P: {npk_recommendations[1]:.2f}, K: {npk_recommendations[2]:.2f}")
|
| 57 |
|
| 58 |
-
# شروع برنامه Streamlit
|
| 59 |
-
if __name__ == '__main__':
|
| 60 |
-
st._main_run_clExplicitMain(True, ['streamlit', 'run', 'app.py'])
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
+
import plotly.express as px
|
|
|
|
| 5 |
from sklearn.ensemble import RandomForestRegressor
|
| 6 |
+
from sklearn.model_selection import train_test_split
|
| 7 |
from sklearn.metrics import mean_squared_error
|
|
|
|
| 8 |
|
| 9 |
+
# مرحله 1: راه اندازی Streamlit و کتابخانهها
|
| 10 |
+
st.title('داشبورد تجزیه و تحلیل نیشکر')
|
| 11 |
|
| 12 |
+
# مرحله 2: آپلود و پردازش دادهها
|
| 13 |
+
uploaded_file = st.file_uploader("آپلود فایل دادهها", type=['csv', 'xlsx', 'pdf', 'tiff'])
|
|
|
|
|
|
|
|
|
|
| 14 |
if uploaded_file is not None:
|
| 15 |
+
# فرض بر این است که فایل CSV است
|
| 16 |
df = pd.read_csv(uploaded_file)
|
| 17 |
+
st.write(df)
|
| 18 |
+
|
| 19 |
+
# مرحله 3: تجسم سه بعدی
|
| 20 |
+
fig = px.scatter_3d(df, x='x_column', y='y_column', z='z_column', color='color_column')
|
| 21 |
+
st.plotly_chart(fig)
|
| 22 |
+
|
| 23 |
+
# مرحله 4: یکپارچه سازی یادگیری ماشین
|
| 24 |
+
X = df[['feature1', 'feature2', 'feature3']] # ویژگیهای مورد نظر
|
| 25 |
+
y = df['target'] # هدف پیشبینی
|
| 26 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 27 |
+
|
| 28 |
+
model = RandomForestRegressor(n_estimators=100)
|
| 29 |
+
model.fit(X_train, y_train)
|
| 30 |
+
y_pred = model.predict(X_test)
|
| 31 |
|
| 32 |
+
st.write('MSE:', mean_squared_error(y_test, y_pred))
|
| 33 |
+
|
| 34 |
+
# توصیههای NPK
|
| 35 |
+
st.write('توصیههای NPK بر اساس پیشبینیها')
|
| 36 |
+
# اینجا کد برای تولید توصیههای NPK بر اساس مدل قرار میگیرد
|
| 37 |
+
|
| 38 |
+
# توجه: این کد فقط یک نمونه است و باید بر اساس دادههای واقعی و نیازهای پروژه تنظیم شود.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
|
|
|
|
|
|
|
|