shaheerawan3 commited on
Commit
e403d05
·
verified ·
1 Parent(s): 3abebba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -25
app.py CHANGED
@@ -39,9 +39,19 @@ st.write(data.tail())
39
 
40
  # Check if 'Close' column exists before converting
41
  if 'Close' in data.columns:
 
 
 
 
 
 
 
 
42
  # Ensure 'Close' prices are numeric and handle any missing values
43
  try:
 
44
  data['Close'] = pd.to_numeric(data['Close'], errors='coerce')
 
45
  data.dropna(subset=['Close'], inplace=True)
46
  except Exception as e:
47
  st.error(f"Error converting 'Close' prices to numeric: {e}")
@@ -67,31 +77,36 @@ if not data.empty and 'Close' in data.columns:
67
 
68
  # Create and fit the Prophet model
69
  m = Prophet()
70
- m.fit(df_train)
71
-
72
- # Create future dataframe and make predictions
73
- future = m.make_future_dataframe(periods=period)
74
- forecast = m.predict(future)
75
-
76
- # Show forecast data and plot forecast
77
- st.subheader('Forecast Data')
78
- st.write(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail())
79
- st.write(f'Forecast plot for the next {n_years} years')
80
-
81
- fig1 = plot_plotly(m, forecast)
82
- st.plotly_chart(fig1)
83
-
84
- # Show forecast components
85
- st.subheader("Forecast Components")
86
- fig2 = m.plot_components(forecast)
87
- st.plotly_chart(fig2)
88
-
89
- # Additional Insights: Displaying key metrics
90
- st.subheader("Key Metrics")
91
- latest_data = forecast.iloc[-1]
92
- st.write(f"Predicted Price: ${latest_data['yhat']:.2f}")
93
- st.write(f"Lower Bound: ${latest_data['yhat_lower']:.2f}")
94
- st.write(f"Upper Bound: ${latest_data['yhat_upper']:.2f}")
 
 
 
 
 
95
 
96
  else:
97
  st.error("No valid data available to make predictions.")
 
39
 
40
  # Check if 'Close' column exists before converting
41
  if 'Close' in data.columns:
42
+ # Check data types of the DataFrame
43
+ st.write("Data Types:")
44
+ st.write(data.dtypes)
45
+
46
+ # Display unique values in the 'Close' column for debugging
47
+ st.write("Unique values in 'Close' column:")
48
+ st.write(data['Close'].unique())
49
+
50
  # Ensure 'Close' prices are numeric and handle any missing values
51
  try:
52
+ # Convert to numeric with coercion for invalid parsing
53
  data['Close'] = pd.to_numeric(data['Close'], errors='coerce')
54
+ # Drop rows with NaN values in 'Close'
55
  data.dropna(subset=['Close'], inplace=True)
56
  except Exception as e:
57
  st.error(f"Error converting 'Close' prices to numeric: {e}")
 
77
 
78
  # Create and fit the Prophet model
79
  m = Prophet()
80
+
81
+ try:
82
+ m.fit(df_train)
83
+
84
+ # Create future dataframe and make predictions
85
+ future = m.make_future_dataframe(periods=period)
86
+ forecast = m.predict(future)
87
+
88
+ # Show forecast data and plot forecast
89
+ st.subheader('Forecast Data')
90
+ st.write(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail())
91
+ st.write(f'Forecast plot for the next {n_years} years')
92
+
93
+ fig1 = plot_plotly(m, forecast)
94
+ st.plotly_chart(fig1)
95
+
96
+ # Show forecast components
97
+ st.subheader("Forecast Components")
98
+ fig2 = m.plot_components(forecast)
99
+ st.plotly_chart(fig2)
100
+
101
+ # Additional Insights: Displaying key metrics
102
+ st.subheader("Key Metrics")
103
+ latest_data = forecast.iloc[-1]
104
+ st.write(f"Predicted Price: ${latest_data['yhat']:.2f}")
105
+ st.write(f"Lower Bound: ${latest_data['yhat_lower']:.2f}")
106
+ st.write(f"Upper Bound: ${latest_data['yhat_upper']:.2f}")
107
+
108
+ except Exception as e:
109
+ st.error(f"Error fitting model: {e}")
110
 
111
  else:
112
  st.error("No valid data available to make predictions.")