<jupyter_start><jupyter_text>Dota Game Prediction<jupyter_code>import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
data=pd.read_csv(r"C:\Users\home\Desktop\Sahiloz\Datasets\dota.txt",header=None)
data.head()
#Find all the games whereupon team 1 won and count the instances of each character
team1wins = data[data[10] == 1]
team1wins = team1wins.drop(columns=[5, 6, 7, 8, 9, 10])
team1wins = pd.DataFrame(team1wins.values.flatten())
charactersTeam1 = team1wins[0].value_counts()
#print(team1wins)
print(charactersTeam1)
#Find all the games whereupon team 2 won and count the instances of each character
team2wins = data[data[10] == 2]
team2wins = team2wins.drop(columns=[0, 1, 2, 3, 4, 10])
team2wins = pd.DataFrame(team2wins.values.flatten())
charactersTeam2 = team2wins[0].value_counts()
print(charactersTeam2)
#merge the two list found above and create a new table
characterWins1 = pd.DataFrame(charactersTeam1)
characterWins2 = pd.DataFrame(charactersTeam2)
characterWins = pd.merge(characterWins1, characterWins2, left_index=True, right_index=True, how='outer' )
#print(characterWins)
characterWins.rename(columns={'0_x':'Team_One','0_y':'Team_Two'}, inplace=True)
#print(characterWins)
characterWins['Total'] = characterWins['Team_One'] + characterWins['Team_Two']
print(characterWins)<jupyter_output>Team_One  Team_Two  Total
Alchemist                359       277    636
Ancient Apparition       267       286    553
Anti-Mage                395       379    774
Axe                      588       508   1096
Bane                     244       234    478
Batrider                 423       403    826
Beastmaster              244       249    493
Bloodseeker              253       226    479
Bounty Hunter            757       739   1496
Brewmaster               251       232    483
Broodmother              146        93    239
<NAME>        340       329    669
Chaos Knight             346       308    654
Chen                     179       166    345
Clinkz                   314       281    595
Clockwerk                399       363    762
Crystal Maiden           405       421    826
Dark Seer                504       463    967
Dazzle                   280       243    523
Death Prophet            202       177    379
Disruptor                347      [...]<jupyter_text>Now to encode the characters we will use the ration of total appearance in winning team to total appearance<jupyter_code>data2 = data.drop(columns=10)
data2 = pd.DataFrame(data2.values.flatten())
totalPlayedChar = data2[0].value_counts()
totalPlayedChar = pd.DataFrame(totalPlayedChar)
#print(totalPlayedChar)
characterWins = pd.merge(characterWins, totalPlayedChar, left_index=True, right_index=True, how='outer' )
characterWins['Win_Rate'] = characterWins['Total'] / characterWins[0]
characterWins.drop(columns=['Team_One','Team_Two','Total' , 0], inplace=True)
print(characterWins)
winRate = characterWins['Win_Rate'].to_dict()
data[0] = data[0].map(winRate)
data[1] = data[1].map(winRate)
data[2] = data[2].map(winRate)
data[3] = data[3].map(winRate)
data[4] = data[4].map(winRate)
data[5] = -data[5].map(winRate)
data[6] = -data[6].map(winRate)
data[7] = -data[7].map(winRate)
data[8] = -data[8].map(winRate)
data[9] = -data[9].map(winRate)
target = data[10]
data.drop(columns=10, inplace=True)
print(data.head())
#using randomforest classifier to train a model
model = RandomForestClassifier(n_estimators=150, random_state=0)
model.fit(data, target)

# User input
K = int(input())      #Enter Number of test cases
for i in range(K):
    userInput = pd.DataFrame([input().split(",")])    #enter comma seperated characters
    userInput[0] = userInput[0].map(winRate)
    userInput[1] = userInput[1].map(winRate)
    userInput[2] = userInput[2].map(winRate)
    userInput[3] = userInput[3].map(winRate)
    userInput[4] = userInput[4].map(winRate)
    userInput[5] = -userInput[5].map(winRate)
    userInput[6] = -userInput[6].map(winRate)
    userInput[7] = -userInput[7].map(winRate)
    userInput[8] = -userInput[8].map(winRate)
    userInput[9] = -userInput[9].map(winRate)
    prediction = model.predict(userInput)
    for i in prediction:
        if i==1:
            print("Team 1 Won This round")
        else:
            print("Team 2 won This Round")<jupyter_output>1
Razor,Kunkka,Drow Ranger,Leshrac,Zeus,Riki,Bane,Visage,Invoker,Timbersaw
Team 1 Won This round
{'fraction_non_alphanumeric': 0.11428571428571428, 'fraction_numerical': 0.06689342403628118, 'mean_word_length': 3.196955280685062, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '510397', 'license': 'MIT', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1481, 'n_words': 340, 'path': 'Dota2prediction.ipynb', 'repo_name': 'Sahil19oz/Machine-Learning-Repo', 'size': '4421'}