Boltuzamaki
commited on
Commit
•
55635e7
1
Parent(s):
8a71435
error handling updated
Browse files
app.py
CHANGED
@@ -46,9 +46,9 @@ def prepare_data(df, forecast_col, forecast_out):
|
|
46 |
y = np.array(label) # Target array
|
47 |
|
48 |
# Check if we have enough data for train-test split
|
49 |
-
if len(
|
50 |
st.error(
|
51 |
-
"Not enough data for training.
|
52 |
)
|
53 |
return None, None, None, None, None
|
54 |
|
@@ -61,10 +61,16 @@ def prepare_data(df, forecast_col, forecast_out):
|
|
61 |
|
62 |
# Button to trigger model generation and prediction
|
63 |
if st.button("Generate"):
|
64 |
-
#
|
65 |
if daysago != "max":
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
67 |
|
|
|
68 |
ticker = yf.Ticker(stock)
|
69 |
data = ticker.history(period=daysago)
|
70 |
|
|
|
46 |
y = np.array(label) # Target array
|
47 |
|
48 |
# Check if we have enough data for train-test split
|
49 |
+
if len(X) < 2 or len(y) < 2: # Need at least two samples to split
|
50 |
st.error(
|
51 |
+
"Not enough data for splitting into training and testing sets. Please adjust the date range or prediction period."
|
52 |
)
|
53 |
return None, None, None, None, None
|
54 |
|
|
|
61 |
|
62 |
# Button to trigger model generation and prediction
|
63 |
if st.button("Generate"):
|
64 |
+
# Ensure the days are in proper format
|
65 |
if daysago != "max":
|
66 |
+
try:
|
67 |
+
# Convert daysago to the correct format recognized by yfinance
|
68 |
+
daysago = str(int(daysago)) + "d"
|
69 |
+
except ValueError:
|
70 |
+
st.error("Invalid time frame. Please enter a number or 'max'.")
|
71 |
+
st.stop()
|
72 |
|
73 |
+
# Fetch stock data
|
74 |
ticker = yf.Ticker(stock)
|
75 |
data = ticker.history(period=daysago)
|
76 |
|