dibend commited on
Commit
010b150
1 Parent(s): b300450

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -13
app.py CHANGED
@@ -5,7 +5,6 @@ from sklearn.linear_model import LinearRegression
5
  import numpy as np
6
  from pandas.tseries.offsets import MonthEnd
7
  import datetime
8
- from scipy import stats
9
 
10
  def plot_and_predict(zip, start_year, start_month, prediction_months):
11
  # Input validation for ZIP code
@@ -53,14 +52,6 @@ def plot_and_predict(zip, start_year, start_month, prediction_months):
53
  future_months = np.array([last_month_index + i for i in range(1, prediction_months + 1)]).reshape(-1, 1)
54
  predicted_prices = model.predict(future_months)
55
 
56
- # Calculate standard error and prediction intervals
57
- se = np.sqrt(np.sum((model.predict(X) - y) ** 2) / (len(y) - 2))
58
- t = stats.t.ppf(0.975, len(y) - 2) # 95% prediction interval
59
- prediction_interval = t * se * np.sqrt(1 + 1/len(y) + (future_months - np.mean(X))**2 / np.sum((X - np.mean(X))**2))
60
-
61
- upper_bound = predicted_prices + prediction_interval
62
- lower_bound = predicted_prices - prediction_interval
63
-
64
  # Prepare data for plotting
65
  historical_prices_trace = go.Scatter(
66
  x=df['Date'],
@@ -80,10 +71,7 @@ def plot_and_predict(zip, start_year, start_month, prediction_months):
80
  fig = go.Figure()
81
  fig.add_trace(historical_prices_trace)
82
  fig.add_trace(predicted_prices_trace)
83
- fig.add_traces([
84
- go.Scatter(x=future_dates, y=upper_bound.flatten(), mode='lines', name='Upper Bound', line=dict(width=0)),
85
- go.Scatter(x=future_dates, y=lower_bound.flatten(), mode='lines', name='Lower Bound', line=dict(width=0), fill='tonexty')
86
- ])
87
  fig.update_layout(
88
  title=f"Real Estate Price Prediction for Zip Code {zip}",
89
  xaxis_title="Date",
 
5
  import numpy as np
6
  from pandas.tseries.offsets import MonthEnd
7
  import datetime
 
8
 
9
  def plot_and_predict(zip, start_year, start_month, prediction_months):
10
  # Input validation for ZIP code
 
52
  future_months = np.array([last_month_index + i for i in range(1, prediction_months + 1)]).reshape(-1, 1)
53
  predicted_prices = model.predict(future_months)
54
 
 
 
 
 
 
 
 
 
55
  # Prepare data for plotting
56
  historical_prices_trace = go.Scatter(
57
  x=df['Date'],
 
71
  fig = go.Figure()
72
  fig.add_trace(historical_prices_trace)
73
  fig.add_trace(predicted_prices_trace)
74
+
 
 
 
75
  fig.update_layout(
76
  title=f"Real Estate Price Prediction for Zip Code {zip}",
77
  xaxis_title="Date",