Kuroshi1

Original Results Predictor

Mar 8th, 2021 (edited)
821
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def predict_results(event):
  2.     """
  3.    Takes an event as a string parameter and uses a decision tree regressor
  4.    to predict the top 3 results given medal and nationality of a competitor
  5.    """
  6.  
  7.     filtered = df_converted[df_converted['Event'] == event]
  8.     filtered = filtered.loc[:, ['Medal', 'Nationality', 'Result']]
  9.     X = filtered.loc[:, filtered.columns != 'Result']
  10.     y = filtered['Result']
  11.     X = pd.get_dummies(X)
  12.  
  13.     (X_train, X_test, y_train, y_test) = train_test_split(X, y,
  14.                                                           test_size=0.35)
  15.     model = DecisionTreeRegressor()
  16.  
  17.     model.fit(X_train, y_train)
  18.     y_test_pred = model.predict(X_test)
  19.     ordered = sorted(y_test_pred.tolist())
  20.  
  21.     if event in field:
  22.  
  23.         events.append(event)
  24.         medals.append('Gold')
  25.         mark.append(convert_from_seconds(ordered[2]))
  26.  
  27.         events.append(event)
  28.         medals.append('Silver')
  29.         mark.append(convert_from_seconds(ordered[1]))
  30.  
  31.         events.append(event)
  32.         medals.append('Bronze')
  33.         mark.append(convert_from_seconds(ordered[0]))
  34.     else:
  35.  
  36.         events.append(event)
  37.         medals.append('Gold')
  38.         mark.append(convert_from_seconds(ordered[0]))
  39.  
  40.         events.append(event)
  41.         medals.append('Silver')
  42.         mark.append(convert_from_seconds(ordered[1]))
  43.  
  44.         events.append(event)
  45.         medals.append('Bronze')
  46.         mark.append(convert_from_seconds(ordered[2]))
  47.  
  48.  
  49. def simulate():
  50.     """
  51.    Predicts the top 3 results for every Olympic event
  52.    Returns a dataframe containing the event name, medal type, and mark of
  53.    each result
  54.    """
  55.     event_array = pd.unique(df_converted['Event'])
  56.  
  57.     for event in event_array:
  58.         predict_results(event)
  59.  
  60.     return pd.DataFrame({'Event': events, 'Medal': medals,
  61.                         'Result': mark})
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×