Chaninder Rishi commited on
Commit
4df6604
1 Parent(s): ac7df46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -1,4 +1,4 @@
1
- #import streamlit as st
2
  import pandas as pd
3
  import numpy as np
4
  import csv
@@ -15,7 +15,7 @@ df = pd.read_csv('emily_election.csv')
15
 
16
  #loaded_model = pickle.load(open(filename, 'rb'))
17
 
18
-
19
  df['runtime'] = df['cumulative_ad_runtime'].apply(lambda s: int(s.split('days')[0]))
20
  df['impressions'] = df['cumulative_impressions_by_region'].apply(lambda d: ast.literal_eval(d))
21
  df['impressions'] = df['impressions'].apply(lambda d: np.array(list(d.values())).sum())
@@ -33,12 +33,11 @@ test = data[~msk]
33
 
34
 
35
  #new_train = train[train['impressions'] < 1000000]
36
- train['spend'] = pd.to_numeric(train['spend'],errors='coerce')
37
 
38
 
39
  new_train = train[(train['spend'] > 250)]
40
  new_train = new_train[new_train['runtime']>4]
41
- new_train.shape
42
 
43
 
44
  #this model predicts impressions given the runtime and the spend
@@ -49,17 +48,14 @@ new_train['log_spend'] = np.log(new_train['spend'])
49
  new_train['log_impressions'] = np.log(new_train['impressions'])
50
  new_train.replace([np.inf, -np.inf], np.nan, inplace=True)
51
  new_train.dropna(inplace=True)
 
52
  x = np.asanyarray(new_train[['log_runtime', 'log_spend']])
53
  y = np.asanyarray(new_train[['log_impressions']])
54
- print(x)
55
- regr.fit(x, y)
56
- #y_pred= regr.predict(new_train[['log_runtime', 'log_spend']])
57
-
58
-
59
- # # The coefficients
60
- #print(regr.coef_)
61
- #print('R-squared score: %.2f' % regr.score(x, y))
62
- #print('Standard Deviation: %.2f' % np.sqrt(sum((y - y_pred)**2) / (len(y) - 2)))
63
-
64
 
 
 
 
65
 
 
 
 
 
1
+ import streamlit as st
2
  import pandas as pd
3
  import numpy as np
4
  import csv
 
15
 
16
  #loaded_model = pickle.load(open(filename, 'rb'))
17
 
18
+ df['spend'] = df['cum_spend']
19
  df['runtime'] = df['cumulative_ad_runtime'].apply(lambda s: int(s.split('days')[0]))
20
  df['impressions'] = df['cumulative_impressions_by_region'].apply(lambda d: ast.literal_eval(d))
21
  df['impressions'] = df['impressions'].apply(lambda d: np.array(list(d.values())).sum())
 
33
 
34
 
35
  #new_train = train[train['impressions'] < 1000000]
36
+ train['spend'] = train['spend'].astype('float')
37
 
38
 
39
  new_train = train[(train['spend'] > 250)]
40
  new_train = new_train[new_train['runtime']>4]
 
41
 
42
 
43
  #this model predicts impressions given the runtime and the spend
 
48
  new_train['log_impressions'] = np.log(new_train['impressions'])
49
  new_train.replace([np.inf, -np.inf], np.nan, inplace=True)
50
  new_train.dropna(inplace=True)
51
+ print(new_train.to_string())
52
  x = np.asanyarray(new_train[['log_runtime', 'log_spend']])
53
  y = np.asanyarray(new_train[['log_impressions']])
 
 
 
 
 
 
 
 
 
 
54
 
55
+ regr.fit(x, y)
56
+ spend = st.number_input('Enter Spend (in dollars): ')
57
+ runtime = st.number_input('Enter runtime (in days)')
58
 
59
+ if spend and runtime:
60
+ pred= regr.predict([np.log([spend, runtime])])
61
+ st.write('70% confidence interval for number of impressions is: {} to {} hits'.format(int(np.exp(pred[0][0]-1.65)), int(np.exp(pred[0][0]+1.65))))