Spaces:
Sleeping
Sleeping
Commit
·
78c7938
1
Parent(s):
b93b419
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,19 +9,19 @@ import os
|
|
| 9 |
|
| 10 |
|
| 11 |
def predictAirPassengers(df, split):
|
| 12 |
-
ts= pd.read_csv('
|
| 13 |
df2 =ts.copy()
|
| 14 |
ttSplit=split/100
|
| 15 |
ts['Month']=pd.to_datetime(ts['Month'])
|
| 16 |
-
ts.rename(columns={'#
|
| 17 |
ts=ts.set_index(['Month'])
|
| 18 |
ts['months'] = [x.month for x in ts.index]
|
| 19 |
ts['years'] = [x.year for x in ts.index]
|
| 20 |
ts.reset_index(drop=True, inplace=True)
|
| 21 |
|
| 22 |
# Split Data
|
| 23 |
-
X=ts.drop("
|
| 24 |
-
Y= ts["
|
| 25 |
X_train=X[:int (len(Y)*ttSplit)]
|
| 26 |
X_test=X[int(len(Y)*ttSplit):]
|
| 27 |
Y_train=Y[:int (len(Y)*ttSplit)]
|
|
@@ -32,11 +32,11 @@ def predictAirPassengers(df, split):
|
|
| 32 |
rf.fit(X_train, Y_train)
|
| 33 |
|
| 34 |
df1=df2.set_index(['Month'])
|
| 35 |
-
df1.rename(columns={'#
|
| 36 |
train=df1.Passengers[:int (len(ts.Passengers)*ttSplit)]
|
| 37 |
test=df1.Passengers[int(len(ts.Passengers)*ttSplit):]
|
| 38 |
preds=rf.predict(X_test).astype(int)
|
| 39 |
-
predictions=pd.DataFrame(preds,columns=['
|
| 40 |
predictions.index=test.index
|
| 41 |
predictions.reset_index(inplace=True)
|
| 42 |
predictions['Month']=pd.to_datetime(predictions['Month'])
|
|
@@ -44,12 +44,12 @@ def predictAirPassengers(df, split):
|
|
| 44 |
|
| 45 |
#combine all into one table
|
| 46 |
ts_df=df.copy()
|
| 47 |
-
ts_df.rename(columns={'#
|
| 48 |
train= ts_df[:int (len(ts_df)*ttSplit)]
|
| 49 |
test= ts_df[int(len(ts_df)*ttSplit):]
|
| 50 |
|
| 51 |
df2['Month']=pd.to_datetime(df2['Month'])
|
| 52 |
-
df2.rename(columns={'#
|
| 53 |
df3= predictions
|
| 54 |
df2['origin']='ground truth'
|
| 55 |
df3['origin']='prediction'
|
|
@@ -64,12 +64,12 @@ demo = gr.Interface(
|
|
| 64 |
gr.Slider(1, 100, value=75, step=1, label="Train test split percentage"),
|
| 65 |
],
|
| 66 |
outputs= [
|
| 67 |
-
gr.LinePlot(x='Month', y='
|
| 68 |
#gr.Timeseries(x='Month')
|
| 69 |
|
| 70 |
],
|
| 71 |
examples=[
|
| 72 |
-
[os.path.join(os.path.abspath(''), "
|
| 73 |
]
|
| 74 |
)
|
| 75 |
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def predictAirPassengers(df, split):
|
| 12 |
+
ts= pd.read_csv('DemandaQuito.csv')
|
| 13 |
df2 =ts.copy()
|
| 14 |
ttSplit=split/100
|
| 15 |
ts['Month']=pd.to_datetime(ts['Month'])
|
| 16 |
+
ts.rename(columns={'#Valor':'Valor'},inplace=True)
|
| 17 |
ts=ts.set_index(['Month'])
|
| 18 |
ts['months'] = [x.month for x in ts.index]
|
| 19 |
ts['years'] = [x.year for x in ts.index]
|
| 20 |
ts.reset_index(drop=True, inplace=True)
|
| 21 |
|
| 22 |
# Split Data
|
| 23 |
+
X=ts.drop("Valor",axis=1)
|
| 24 |
+
Y= ts["Valor"]
|
| 25 |
X_train=X[:int (len(Y)*ttSplit)]
|
| 26 |
X_test=X[int(len(Y)*ttSplit):]
|
| 27 |
Y_train=Y[:int (len(Y)*ttSplit)]
|
|
|
|
| 32 |
rf.fit(X_train, Y_train)
|
| 33 |
|
| 34 |
df1=df2.set_index(['Month'])
|
| 35 |
+
df1.rename(columns={'#Valor':'Valor'},inplace=True)
|
| 36 |
train=df1.Passengers[:int (len(ts.Passengers)*ttSplit)]
|
| 37 |
test=df1.Passengers[int(len(ts.Passengers)*ttSplit):]
|
| 38 |
preds=rf.predict(X_test).astype(int)
|
| 39 |
+
predictions=pd.DataFrame(preds,columns=['Valor'])
|
| 40 |
predictions.index=test.index
|
| 41 |
predictions.reset_index(inplace=True)
|
| 42 |
predictions['Month']=pd.to_datetime(predictions['Month'])
|
|
|
|
| 44 |
|
| 45 |
#combine all into one table
|
| 46 |
ts_df=df.copy()
|
| 47 |
+
ts_df.rename(columns={'#Valor':'Valor'},inplace=True)
|
| 48 |
train= ts_df[:int (len(ts_df)*ttSplit)]
|
| 49 |
test= ts_df[int(len(ts_df)*ttSplit):]
|
| 50 |
|
| 51 |
df2['Month']=pd.to_datetime(df2['Month'])
|
| 52 |
+
df2.rename(columns={'#Valor':'Valor'},inplace=True)
|
| 53 |
df3= predictions
|
| 54 |
df2['origin']='ground truth'
|
| 55 |
df3['origin']='prediction'
|
|
|
|
| 64 |
gr.Slider(1, 100, value=75, step=1, label="Train test split percentage"),
|
| 65 |
],
|
| 66 |
outputs= [
|
| 67 |
+
gr.LinePlot(x='Month', y='Valor', color='origin')
|
| 68 |
#gr.Timeseries(x='Month')
|
| 69 |
|
| 70 |
],
|
| 71 |
examples=[
|
| 72 |
+
[os.path.join(os.path.abspath(''), "DemandaQuito_dt.csv"), 75],
|
| 73 |
]
|
| 74 |
)
|
| 75 |
|