<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mandvi Bhadouriya</title>
    <description>The latest articles on DEV Community by Mandvi Bhadouriya (@mandvieng).</description>
    <link>https://dev.to/mandvieng</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F600383%2F64656580-8807-483e-9f91-6ee6e265b150.jpeg</url>
      <title>DEV Community: Mandvi Bhadouriya</title>
      <link>https://dev.to/mandvieng</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mandvieng"/>
    <language>en</language>
    <item>
      <title>Base ball</title>
      <dc:creator>Mandvi Bhadouriya</dc:creator>
      <pubDate>Sun, 21 Mar 2021 05:23:19 +0000</pubDate>
      <link>https://dev.to/mandvieng/base-ball-3p0f</link>
      <guid>https://dev.to/mandvieng/base-ball-3p0f</guid>
      <description>&lt;p&gt;Readme of my project :-&lt;/p&gt;

&lt;h1&gt;
  
  
  Machine-Learning-Baseball ⚾
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Baseball
&lt;/h2&gt;

&lt;p&gt;The movie Money Ball, which is based on a true story, shows in game baseball statistics can be collected and analyzed in such a way that provides accurate answers to specific questions. This relies on the fact that, over the course of a season, teams experience patterns and react to factors in a repetitive manner, this ultimately affects their in-game performances. Essentially, the MLB is one large complexity system with feedback, stocks, and other system qualities as a result it can theoretically be understood.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hypothesis
&lt;/h2&gt;

&lt;p&gt;We theorized that there is indeed a relationship between the statistics to a game and its outcome. As a result, the group focused on implementing a model that predicted the score of a particular game using the statistics of that game.&lt;/p&gt;

&lt;h2&gt;
  
  
  Model Overview
&lt;/h2&gt;

&lt;p&gt;Both the teams in a game are given their individual ID values and are made into vectors. Relevant data like the home and away team, home runs, RBI’s, and walk’s are all taken into account and passed through layers. There’s no need to reinvent the wheel here, there's a multitude of libraries that enable a coder to implement machine learning theories efficiently. In this case we will be using a library called TFlearn, documentation available from &lt;a href="http://tflearn.org"&gt;http://tflearn.org&lt;/a&gt;. The program will output the home and away teams as well as their respective score predictions.&lt;/p&gt;

&lt;p&gt;## Implementation&lt;br&gt;
 As mentioned earlier, the model was built using TFLearn, which is a API to Tensorflow. The model’s input data is the 2020/2021 baseball season statistics, score, and matchups. The model learns what statistics are useful for deciding a score, it also recognizes the different team by feeding the teams ID into a separate layer first. To train the model we used back propagation with gradient descent, this was handled by TFLearn during the training process. An in depth description of the model used is given in the notebook that is proved with the report. We chose to train the model on the 2020 season, using that data to learn what statistics are import in a game, that trained model could then make a predictions. We applied the model to the 2021 season, for each game we gave the model the statistics, scores and teams in that game to base a prediction from, even though the statistic are not determined until after a game. We originally tried using input as the team's average statistics for all their previous games, however these predictions were no better than coin flip.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;In the end the model predicted games quite well. Scores were within 1 or 2 points off the actual values for the score and have about a 90% prediction rate of who would win games. The high accuracy of the model helps prove the hypothesis that baseball game statistics are highly correlated to the final score of the game. Such that the amount of home runs a team achieves in a game, has an direct effect of high there score is. Also when team achieves more hits than their opponent, they have a higher probability of scoring more runs than the other team. For defence, if a team completes a substantial amount of double plays in a game, then it demonstrates that there defense is effective, and that the other team will have a harder time scoring runs. The neural net was able to detect these subtle relations, to make effective predictions on who wins the game, and what the score is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code of my project :-
&lt;/h2&gt;

&lt;p&gt;Code is written in Python programming language :Make sure make .py file to execute following code&lt;br&gt;
import numpy as np&lt;/p&gt;

&lt;p&gt;class GameStats(object):          &lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def &lt;strong&gt;init&lt;/strong&gt;(self, homeTeamNameIndex, homeTeamScoreIndex, homeTeamStatsIndex, visitorTeamNameIndex, visitorTeamScoreIndex, visitorTeamStatsIndex):&lt;br&gt;
    #parse the text file&lt;br&gt;
    self.statsFile = open("baseball2016.txt", "r")&lt;br&gt;
    self.topArray = []&lt;br&gt;
    self.sideArray = []&lt;br&gt;&lt;br&gt;
    self.sc = np.zeros((30,30,30), np.int32) &lt;br&gt;
    self.sc[:,:,:] = -1&lt;br&gt;&lt;br&gt;
    self.am = np.zeros((30,30), np.float32)&lt;br&gt;
    self.gameList = []
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for line in self.statsFile:
    homeTeam = ""
    awayTeam = ""
    homeScore = 0
    awayScore = 0

    token = line.split(',')  #tokenize the string
    tokenIndex = [homeTeamNameIndex, homeTeamScoreIndex, visitorTeamNameIndex, visitorTeamScoreIndex] + [i for i in homeTeamStatsIndex] + [i for i in visitorTeamStatsIndex]
    attributes = dict()

    for i in xrange(len(token)):
        if(i in tokenIndex):
            attributes[i] = removeQuotes(token[i])

    self.addScore(attributes[homeTeamNameIndex], attributes[visitorTeamNameIndex], attributes[homeTeamScoreIndex], attributes[visitorTeamScoreIndex])

    self.addGame(attributes[homeTeamNameIndex], attributes[homeTeamScoreIndex], [attributes[i] for i in homeTeamStatsIndex], attributes[visitorTeamNameIndex], attributes[visitorTeamScoreIndex], [attributes[i] for i in homeTeamStatsIndex])

self.buildAvgMatrix()
self.statsFile.close()      
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;def removeQuotes(string):&lt;br&gt;
    if (string.startswith('"') and string.endswith('"')) or (string.startswith("'") and string.endswith("'")):&lt;br&gt;
        print("here")&lt;br&gt;
        return string[1:-1]&lt;br&gt;
    return string  &lt;/p&gt;

&lt;p&gt;def addGame(self, team1, score1, stats1, team2, score2, stats2):&lt;br&gt;
    self.gameList.append([team1, score1, stats1, team2, score2, stats2])&lt;/p&gt;
&lt;h1&gt;
  
  
  give it two teams, the scores, and it will add it to the matrix
&lt;/h1&gt;

&lt;p&gt;def addScore(self, team1, team2, score1, score2):&lt;br&gt;
    '''&lt;br&gt;
    for a team in top array, the index in the array corrisponds to the matrix column there located in&lt;br&gt;
    for a team in side array, the index in the array corrisponds to the matrix row there located in&lt;br&gt;
    '''&lt;br&gt;
    #team 1 score entry&lt;br&gt;
    try:&lt;br&gt;
        row = self.sideArray.index(team2)    &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;except:
    self.sideArray.append(team2)
    row = self.sideArray.index(team2)    

try:
    col = self.topArray.index(team1)
except:
    self.topArray.append(team1)
    col = self.topArray.index(team1)
temp = self.sc[row, col]
counter = 0
for e in temp:
    if (e == -1):
        temp[counter] = score1
        break
    counter += 1
self.sc[row, col] = temp

#team 2 score entry
try:
    row = self.sideArray.index(team1)    
except:
    self.sideArray.append(team1)
    row = self.sideArray.index(team1)    

try:
    col = self.topArray.index(team2)
except:
    self.topArray.append(team2)
    col = self.topArray.index(team2)
temp = self.sc[row, col]
counter = 0
for e in temp:
    if (e == -1):
        temp[counter] = score2
        break
    counter += 1
self.sc[row, col] = temp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  returns the score(s) for match up
&lt;/h1&gt;

&lt;p&gt;def getScore(self, team1, team2, gameSelect = None):&lt;br&gt;
    print(team1, team2)&lt;br&gt;
    try:&lt;br&gt;
        score1 = self.sc[self.sideArray.index(team2), self.topArray.index(team1)]&lt;br&gt;
        score2 = self.sc[self.sideArray.index(team1), self.topArray.index(team2)]&lt;br&gt;
        if (gameSelect == None):&lt;br&gt;
            print(team1, score1)&lt;br&gt;
            print(team2, score2)&lt;br&gt;
        else:&lt;br&gt;
            print(team1, score1[gameSelect])&lt;br&gt;
            print(team2, score2[gameSelect])&lt;br&gt;
    except:&lt;br&gt;
        print('Invalid input of teams')&lt;/p&gt;

&lt;p&gt;def getGameList(self):&lt;br&gt;
    return self.gameList&lt;/p&gt;
&lt;h1&gt;
  
  
  constructs a matrix of the avg score in a matchup
&lt;/h1&gt;

&lt;p&gt;def buildAvgMatrix(self): &lt;br&gt;
    for col in range(len(self.sc[:,0])):   #depth&lt;br&gt;
        for row in range(len(self.sc[0, :])):  #width&lt;br&gt;
            tempScore = self.sc[row, col]&lt;br&gt;
            avgScore = 0.0&lt;br&gt;
            count = 0.0&lt;br&gt;
            for j in tempScore:&lt;br&gt;
                if (j != -1):&lt;br&gt;
                    avgScore += j&lt;br&gt;
                    count += 1&lt;br&gt;
                else:&lt;br&gt;
                    break&lt;br&gt;
            try:&lt;br&gt;
                avgScore = avgScore / count&lt;br&gt;
            except:&lt;br&gt;
                avgScore = -1&lt;br&gt;
            self.am[row, col] = avgScore&lt;/p&gt;
&lt;h1&gt;
  
  
  get the value of the avg score for a match up
&lt;/h1&gt;

&lt;p&gt;def getAvgScore(self, team1, team2):&lt;br&gt;
    try:&lt;br&gt;
        score1 = self.am[self.sideArray.index(team2), self.topArray.index(team1)]&lt;br&gt;
        score2 = self.am[self.sideArray.index(team1), self.topArray.index(team2)]&lt;br&gt;
        print(team1, score1)&lt;br&gt;
        print(team2, score2)&lt;br&gt;&lt;br&gt;
    except:&lt;br&gt;
        print('Invalid input of teams')&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Baseball Format guide&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Field(s)  Meaning&lt;br&gt;
    1     Date in the form "yyyymmdd"&lt;br&gt;
    2     Number of game:&lt;br&gt;
             "0" -- a single game&lt;br&gt;
             "1" -- the first game of a double (or triple) header&lt;br&gt;
                    including seperate admission doubleheaders&lt;br&gt;
             "2" -- the second game of a double (or triple) header&lt;br&gt;
                    including seperate admission doubleheaders&lt;br&gt;
             "3" -- the third game of a triple-header&lt;br&gt;
             "A" -- the first game of a double-header involving 3 teams&lt;br&gt;
             "B" -- the second game of a double-header involving 3 teams&lt;br&gt;
    3     Day of week  ("Sun","Mon","Tue","Wed","Thu","Fri","Sat")&lt;br&gt;
  4-5     Visiting team and league&lt;br&gt;
    6     Visiting team game number&lt;br&gt;
          For this and the home team game number, ties are counted as&lt;br&gt;
          games and suspended games are counted from the starting&lt;br&gt;
          rather than the ending date.&lt;br&gt;
  7-8     Home team and league&lt;br&gt;
    9     Home team game number&lt;br&gt;
10-11     Visiting and home team score (unquoted)&lt;br&gt;
   12     Length of game in outs (unquoted).  A full 9-inning game would&lt;br&gt;
          have a 54 in this field.  If the home team won without batting&lt;br&gt;
          in the bottom of the ninth, this field would contain a 51.&lt;br&gt;
   13     Day/night indicator ("D" or "N")&lt;br&gt;
   14     Completion information.  If the game was completed at a&lt;br&gt;
          later date (either due to a suspension or an upheld protest)&lt;br&gt;
          this field will include:&lt;br&gt;
             "yyyymmdd,park,vs,hs,len" Where&lt;br&gt;
          yyyymmdd -- the date the game was completed&lt;br&gt;
          park -- the park ID where the game was completed&lt;br&gt;
          vs -- the visitor score at the time of interruption&lt;br&gt;
          hs -- the home score at the time of interruption&lt;br&gt;
          len -- the length of the game in outs at time of interruption&lt;br&gt;
          All the rest of the information in the record refers to the&lt;br&gt;
          entire game.&lt;br&gt;
   15     Forfeit information:&lt;br&gt;
             "V" -- the game was forfeited to the visiting team&lt;br&gt;
             "H" -- the game was forfeited to the home team&lt;br&gt;
             "T" -- the game was ruled a no-decision&lt;br&gt;
   16     Protest information:&lt;br&gt;
             "P" -- the game was protested by an unidentified team&lt;br&gt;
             "V" -- a disallowed protest was made by the visiting team&lt;br&gt;
             "H" -- a disallowed protest was made by the home team&lt;br&gt;
             "X" -- an upheld protest was made by the visiting team&lt;br&gt;
             "Y" -- an upheld protest was made by the home team&lt;br&gt;
          Note: two of these last four codes can appear in the field&lt;br&gt;
          (if both teams protested the game).&lt;br&gt;
   17     Park ID&lt;br&gt;
   18     Attendance (unquoted)&lt;br&gt;
   19     Time of game in minutes (unquoted)&lt;br&gt;
20-21     Visiting and home line scores.  For example:&lt;br&gt;
             "010000(10)0x"&lt;br&gt;
          Would indicate a game where the home team scored a run in&lt;br&gt;
          the second inning, ten in the seventh and didn't bat in the&lt;br&gt;
          bottom of the ninth.&lt;br&gt;
22-38     Visiting team offensive statistics (unquoted) (in order):&lt;br&gt;
             at-bats&lt;br&gt;
             hits&lt;br&gt;
             doubles&lt;br&gt;
             triples&lt;br&gt;
             homeruns&lt;br&gt;
             RBI&lt;br&gt;
             sacrifice hits.  This may include sacrifice flies for years&lt;br&gt;
                prior to 1954 when sacrifice flies were allowed.&lt;br&gt;
             sacrifice flies (since 1954)&lt;br&gt;
             hit-by-pitch&lt;br&gt;
             walks&lt;br&gt;
             intentional walks&lt;br&gt;
             strikeouts&lt;br&gt;
             stolen bases&lt;br&gt;
             caught stealing&lt;br&gt;
             grounded into double plays&lt;br&gt;
             awarded first on catcher's interference&lt;br&gt;
             left on base&lt;br&gt;
39-43     Visiting team pitching statistics (unquoted)(in order):&lt;br&gt;
             pitchers used ( 1 means it was a complete game )&lt;br&gt;
             individual earned runs&lt;br&gt;
             team earned runs&lt;br&gt;
             wild pitches&lt;br&gt;
             balks&lt;br&gt;
44-49     Visiting team defensive statistics (unquoted) (in order):&lt;br&gt;
             putouts.  Note: prior to 1931, this may not equal 3 times&lt;br&gt;
                the number of innings pitched.  Prior to that, no&lt;br&gt;
                putout was awarded when a runner was declared out for&lt;br&gt;
                being hit by a batted ball.&lt;br&gt;
             assists&lt;br&gt;
             errors&lt;br&gt;
             passed balls&lt;br&gt;
             double plays&lt;br&gt;
             triple plays&lt;br&gt;
50-66     Home team offensive statistics&lt;br&gt;
67-71     Home team pitching statistics&lt;br&gt;
72-77     Home team defensive statistics&lt;br&gt;
78-79     Home plate umpire ID and name&lt;br&gt;
80-81     1B umpire ID and name&lt;br&gt;
82-83     2B umpire ID and name&lt;br&gt;
84-85     3B umpire ID and name&lt;br&gt;
86-87     LF umpire ID and name&lt;br&gt;
88-89     RF umpire ID and name&lt;br&gt;
          If any umpire positions were not filled for a particular game&lt;br&gt;
          the fields will be "","(none)".&lt;br&gt;
90-91     Visiting team manager ID and name&lt;br&gt;
92-93     Home team manager ID and name&lt;br&gt;
94-95     Winning pitcher ID and name&lt;br&gt;
96-97     Losing pitcher ID and name&lt;br&gt;
98-99     Saving pitcher ID and name--"","(none)" if none awarded&lt;br&gt;
100-101   Game Winning RBI batter ID and name--"","(none)" if none&lt;br&gt;
          awarded&lt;br&gt;
102-103   Visiting starting pitcher ID and name&lt;br&gt;
104-105   Home starting pitcher ID and name&lt;br&gt;
106-132   Visiting starting players ID, name and defensive position,&lt;br&gt;
          listed in the order (1-9) they appeared in the batting order.&lt;br&gt;
133-159   Home starting players ID, name and defensive position&lt;br&gt;
          listed in the order (1-9) they appeared in the batting order.&lt;br&gt;
  160     Additional information.  This is a grab-bag of informational&lt;br&gt;
          items that might not warrant a field on their own.  The field &lt;br&gt;
          is alpha-numeric. Some items are represented by tokens such as:&lt;br&gt;
             "HTBF" -- home team batted first.&lt;br&gt;
             Note: if "HTBF" is specified it would be possible to see&lt;br&gt;
             something like "01002000x" in the visitor's line score.&lt;br&gt;
          Changes in umpire positions during a game will also appear in &lt;br&gt;
          this field.  These will be in the form:&lt;br&gt;
             umpchange,inning,umpPosition,umpid with the latter three&lt;br&gt;
             repeated for each umpire.&lt;br&gt;
          These changes occur with umpire injuries, late arrival of &lt;br&gt;
          umpires or changes from completion of suspended games. Details&lt;br&gt;
          of suspended games are in field 14.&lt;br&gt;
  161     Acquisition information:&lt;br&gt;
             "Y" -- we have the complete game&lt;br&gt;
             "N" -- we don't have any portion of the game&lt;br&gt;
             "D" -- the game was derived from box score and game story&lt;br&gt;
             "P" -- we have some portion of the game.  We may be missing&lt;br&gt;
                    innings at the beginning, middle and end of the game.&lt;/p&gt;

&lt;p&gt;Missing fields will be NULL.&lt;br&gt;
&lt;br&gt;
I have used Pycharm IDE and interpreter Python 3.9 (pythonProject) to make this project.&lt;/p&gt;

&lt;h3&gt;
  
  
  This was my gaming project. I dont know how to upload video. So I am sorry to upload my video here. If I had made any mistake , I am sorry, please excuse me.
&lt;/h3&gt;

&lt;p&gt;Thanks &lt;br&gt;
Mandvi&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>baseball</category>
      <category>mandvi</category>
      <category>sashido</category>
    </item>
    <item>
      <title>geek week local</title>
      <dc:creator>Mandvi Bhadouriya</dc:creator>
      <pubDate>Sat, 20 Mar 2021 08:35:01 +0000</pubDate>
      <link>https://dev.to/mandvieng/geek-week-local-4ilc</link>
      <guid>https://dev.to/mandvieng/geek-week-local-4ilc</guid>
      <description>&lt;p&gt;Today, geek week local event is going to bind up today. This event was very helpful to us. We learnt here many new things such as machine learning , artificial intelligence , data structure and algorithms, many coding websites, android studio , GitHub, lobe, excel, data visualization, and many things. We have made many profiles on many social media platforms. &lt;/p&gt;

</description>
      <category>geekweeklocal</category>
      <category>event</category>
      <category>sharing</category>
      <category>learnings</category>
    </item>
  </channel>
</rss>
