Technical Machine's team building algorithm works in a few steps. It begins by selecting the most likely remaining Pokemon on the team given what it has already seen. It then adds items / moves to each Pokemon. Finally, it creates an optimized EV spread.
The AI predicts the foe's team using the usage stats. The first step is to simply look at usage stats overall, and that is the initial estimate. This estimate is then refined using various multipliers.
The first multiplier for the Pokemon is the non-lead multiplier. Whenever my AI has seen a team, It has always seen at least one Pokemon: the lead. We have lead stats for Pokemon, and so we can remove that from the general stats and get a non-lead multiplier. For instance, if Pidgey is used 100 times total, and is used 40 times as a lead, that means if I don't see it as a lead, it actually only has 60% of the usages that the overall stats suggest.
The next multiplier comes from the teammate stats. As an example, I will use a particular point in time in Generation 4. Machamp is 12.98% of all Pokemon used. If I have seen Celebi, however, then it is used 16.9% of the time, or about 1.3 times as much. If I then see a Gengar, Machamp is only used .92 times as much as you might expect Machamp to be used alone. Combining all of these gives 12.98% * 1.3 * .92 = 15.54% of all Pokemon used with Celebi and Gengar are Machamp. After taking all of these multipliers into account, I find which Pokemon is the most likely to be used, and assume that Pokemon is next on the team. I then see which Pokemon is made most likely by the inclusion of that Pokemon, and continue repeating this process until the entire team has been predicted.
In versions of Pokemon with team reveal, this is much less important, as all 6 Pokemon are known. However, there are variants with team reveal in which players select a subset of the visible 6, and therefore a strong player should be able to make use of this information to select the best subset. Even if all Pokemon are brought into battle (see 6, choose 6), there is still the issue of determining which Pokemon should lead.
There is no equivalent to "team mate stats" for move usages, however, and team reveal does not invalidate work in this domain. Currently, my move set predictor simply takes the top 4 moves used by the given Pokemon and assumes that's what they have. If a Pokemon uses a different move, Technical Machine removes the least commonly used move to make room. This could lead to, for example, predicting that Heatran has both Flamethrower and Fire Blast if the AI sees Flamethrower; the default prediction actually does give a pretty good move set most of the time, however. Most Pokemon have a top 4 set of moves that make a solid move set. If Technical Machine could get the equivalent of "team mate stats" for moves, then it could do more to predict properly.
Technical Machine simply uses the most used ability / item as its prediction for what the foe has. However, there are certain situations where Techincal Machine can use evidence in the battle to correct that. Technical Machine is currently limited to things that give an obvious message, such as Leftovers or Black Sludge. Technical Machine is not yet smart enough to see that the foe has changed moves without switching and thus cannot be using a choice item, nor is it smart enough to calculate damage and see that they must be using a Choice Band. I actually have written a "reverse damage calculator" that could do calculations like that, including finding exact EVs, but it takes far too long to calculate to be useful in a battle situation.
This is the one part of the team builder that Technical Machine relies more on mathematical analysis than usage stats. Technical Machine has two components for this:
Technical Machine runs those two steps repeatedly until the optimizing step can no longer find any waste to remove.
In each of these steps, Technical Machine performs the same process with every nature. It then combines the results from each step, added up the EVs required for each nature. It then picks the EV / nature combination that uses the fewest EVs.
Technical Machine currently randomly divides all remaining EVs among each stat. However, my plans for the future are to weight this random padding by how often that particular EV is used by that Pokemon. In other words, a Pokemon that generally invests a lot in Speed is more likely to have its Speed EVs padded than a Pokemon that rarely puts a single EV into Speed.
Technical Machine has two methods of making a team. The first is essentially a team thief. If the AI loses against someone, it stores their team. It uses whatever it has seen as the base of the team, and then it runs their team through the team predictor / EV optimizer to fill in the gaps / improve it.
The other method is a bit more manual. I have built a stand-alone team builder / predictor program. You can enter in as much or as little data as you like, and Technical Machine fills in the rest. It uses the team prediction algorithms outlined above with one important exception. The team builder has a field for how "random" you want the team to be. This number determines how many Pokemon to pick on a randomly weighted selection rather than just the most likely. A randomly generated Pokemon is weighted by how likely it is to appear, based on the Pokemon seen so far, rather than having Technical Machine simply pick the most likely. You could generate a team by this method (you don't even have to fill in a single Pokemon) and save that team for TM's later use.
Technical Machine currently supports battling with one specific team or with every team in a given directory (weighted equally). The random team selection is probably the best method, as this should give Technical Machine the advantage of not being able to be counter-teamed, as it would load a new team for each battle.
This is an old version of the team predictor, but it shows the general use.
The following are the predicted teams based on the 2010 August statistics. The only data these predictions are given is the lead Pokemon. Data will be sorted by lead frequency.
Azelf @ Focus Sash Ability: Levitate - Taunt - Psychic - Stealth Rock - Explosion Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake Gyarados @ Leftovers Ability: Intimidate - Earthquake - Stone Edge - Dragon Dance - Waterfall Gengar @ Life Orb Ability: Levitate - Substitute - Thunderbolt - Focus Blast - Shadow Ball
Machamp @ Lum Berry Ability: No Guard - Ice Punch - Bullet Punch - Payback - DynamicPunch Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Gyarados @ Leftovers Ability: Intimidate - Earthquake - Stone Edge - Dragon Dance - Waterfall Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake Jirachi @ Leftovers Ability: Serene Grace - Ice Punch - Thunderbolt - Fire Punch - Iron Head Rotom-H @ Leftovers Ability: Levitate - Trick - Overheat - Thunderbolt - Shadow Ball
Aerodactyl @ Focus Sash Ability: Pressure - Rock Slide - Stealth Rock - Taunt - Earthquake Gengar @ Life Orb Ability: Levitate - Substitute - Thunderbolt - Focus Blast - Shadow Ball Tyranitar @ Choice Scarf Ability: Sand Stream - Pursuit - Earthquake - Stone Edge - Crunch Magnezone @ Leftovers Ability: Magnet Pull - Hidden Power - Substitute - Explosion - Thunderbolt Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Starmie @ Life Orb Ability: Natural Cure - Rapid Spin - Surf - Ice Beam - Thunderbolt
Metagross @ Lum Berry Ability: Clear Body - Bullet Punch - Explosion - Meteor Mash - Earthquake Gyarados @ Leftovers Ability: Intimidate - Earthquake - Stone Edge - Dragon Dance - Waterfall Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Starmie @ Life Orb Ability: Natural Cure - Rapid Spin - Surf - Ice Beam - Thunderbolt
Swampert @ Leftovers Ability: Torrent - Roar - Ice Beam - Stealth Rock - Earthquake Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake Rotom-H @ Leftovers Ability: Levitate - Trick - Overheat - Thunderbolt - Shadow Ball Starmie @ Life Orb Ability: Natural Cure - Rapid Spin - Surf - Ice Beam - Thunderbolt
Infernape @ Life Orb Ability: Blaze - U-turn - Fire Blast - Grass Knot - Close Combat Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Starmie @ Life Orb Ability: Natural Cure - Rapid Spin - Surf - Ice Beam - Thunderbolt Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake Gengar @ Life Orb Ability: Levitate - Substitute - Thunderbolt - Focus Blast - Shadow Ball Gyarados @ Leftovers Ability: Intimidate - Earthquake - Stone Edge - Dragon Dance - Waterfall
Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake Gyarados @ Leftovers Ability: Intimidate - Earthquake - Stone Edge - Dragon Dance - Waterfall Gengar @ Life Orb Ability: Levitate - Substitute - Thunderbolt - Focus Blast - Shadow Ball Starmie @ Life Orb Ability: Natural Cure - Rapid Spin - Surf - Ice Beam - Thunderbolt
Jirachi @ Leftovers Ability: Serene Grace - Ice Punch - Thunderbolt - Fire Punch - Iron Head Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake Rotom-W @ Leftovers Ability: Levitate - Trick - Thunderbolt - Hydro Pump - Shadow Ball Suicune @ Leftovers Ability: Pressure - Hidden Power - Ice Beam - Surf - Calm Mind Roserade @ Focus Sash Ability: Natural Cure - Hidden Power - Leaf Storm - Sleep Powder - Toxic Spikes
Ninjask @ Leftovers Ability: Speed Boost - X-Scissor - Substitute - Swords Dance - Baton Pass Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Starmie @ Life Orb Ability: Natural Cure - Rapid Spin - Surf - Ice Beam - Thunderbolt Dragonite @ Life Orb Ability: Inner Focus - Outrage - ExtremeSpeed - Dragon Dance - Earthquake Metagross @ Lum Berry Ability: Clear Body - Bullet Punch - Explosion - Meteor Mash - Earthquake Gengar @ Life Orb Ability: Levitate - Substitute - Thunderbolt - Focus Blast - Shadow Ball
Roserade @ Focus Sash Ability: Natural Cure - Hidden Power - Leaf Storm - Sleep Powder - Toxic Spikes Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Rotom-W @ Leftovers Ability: Levitate - Trick - Thunderbolt - Hydro Pump - Shadow Ball Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake Suicune @ Leftovers Ability: Pressure - Hidden Power - Ice Beam - Surf - Calm Mind Jirachi @ Leftovers Ability: Serene Grace - Ice Punch - Thunderbolt - Fire Punch - Iron Head
Hippowdon @ Leftovers Ability: Sand Stream - Roar - Stealth Rock - Slack Off - Earthquake Blissey @ Leftovers Ability: Natural Cure - Wish - Toxic - Softboiled - Seismic Toss Skarmory @ Leftovers Ability: Keen Eye - Brave Bird - Whirlwind - Spikes - Roost Tentacruel @ Leftovers Ability: Liquid Ooze - Sludge Bomb - Toxic Spikes - Surf - Rapid Spin Rotom-H @ Leftovers Ability: Levitate - Trick - Overheat - Thunderbolt - Shadow Ball Swampert @ Leftovers Ability: Torrent - Roar - Ice Beam - Stealth Rock - Earthquake
Starmie @ Life Orb Ability: Natural Cure - Rapid Spin - Surf - Ice Beam - Thunderbolt Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake Gengar @ Life Orb Ability: Levitate - Substitute - Thunderbolt - Focus Blast - Shadow Ball Gyarados @ Leftovers Ability: Intimidate - Earthquake - Stone Edge - Dragon Dance - Waterfall
Dragonite @ Life Orb Ability: Inner Focus - Outrage - ExtremeSpeed - Dragon Dance - Earthquake Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Starmie @ Life Orb Ability: Natural Cure - Rapid Spin - Surf - Ice Beam - Thunderbolt Gengar @ Life Orb Ability: Levitate - Substitute - Thunderbolt - Focus Blast - Shadow Ball Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake
Tyranitar @ Choice Scarf Ability: Sand Stream - Pursuit - Earthquake - Stone Edge - Crunch Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Gyarados @ Leftovers Ability: Intimidate - Earthquake - Stone Edge - Dragon Dance - Waterfall Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake Gengar @ Life Orb Ability: Levitate - Substitute - Thunderbolt - Focus Blast - Shadow Ball
Uxie @ Choice Scarf Ability: Levitate - Trick - Thunder Wave - U-turn - Stealth Rock Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Flygon @ Choice Scarf Ability: Levitate - Stone Edge - Outrage - U-turn - Earthquake Suicune @ Leftovers Ability: Pressure - Hidden Power - Ice Beam - Surf - Calm Mind Jirachi @ Leftovers Ability: Serene Grace - Ice Punch - Thunderbolt - Fire Punch - Iron Head Rotom-H @ Leftovers Ability: Levitate - Trick - Overheat - Thunderbolt - Shadow Ball
Forretress @ Leftovers Ability: Sturdy - Toxic Spikes - Explosion - Spikes - Rapid Spin Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Gyarados @ Leftovers Ability: Intimidate - Earthquake - Stone Edge - Dragon Dance - Waterfall Blissey @ Leftovers Ability: Natural Cure - Wish - Toxic - Softboiled - Seismic Toss Rotom-H @ Leftovers Ability: Levitate - Trick - Overheat - Thunderbolt - Shadow Ball Skarmory @ Leftovers Ability: Keen Eye - Brave Bird - Whirlwind - Spikes - Roost
Smeargle @ Focus Sash Ability: Own Tempo - Substitute - Ingrain - Baton Pass - Spore Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Vaporeon @ Leftovers Ability: Water Absorb - Hidden Power - Protect - Wish - Surf Lucario @ Life Orb Ability: Inner Focus - Crunch - Swords Dance - ExtremeSpeed - Close Combat Zapdos @ Leftovers Ability: Pressure - Hidden Power - Heat Wave - Roost - Thunderbolt Celebi @ Leftovers Ability: Natural Cure - Leaf Storm - Thunder Wave - Grass Knot - Recover
Gliscor @ Leftovers Ability: Sand Veil - Stealth Rock - Taunt - Roost - Earthquake Tyranitar @ Choice Scarf Ability: Sand Stream - Pursuit - Earthquake - Stone Edge - Crunch Scizor @ Choice Band Ability: Technician - Pursuit - U-turn - Superpower - Bullet Punch Heatran @ Choice Scarf Ability: Flash Fire - Dragon Pulse - Explosion - Fire Blast - Earth Power Gyarados @ Leftovers Ability: Intimidate - Earthquake - Stone Edge - Dragon Dance - Waterfall Rotom-H @ Leftovers Ability: Levitate - Trick - Overheat - Thunderbolt - Shadow Ball
Bronzong @ Leftovers Ability: Levitate - Earthquake - Stealth Rock - Gyro Ball - Explosion Kingdra @ Leftovers Ability: Swift Swim - Rain Dance - Dragon Dance - Outrage - Waterfall Ludicolo @ Life Orb Ability: Swift Swim - Energy Ball - Rain Dance - Ice Beam - Surf Kabutops @ Life Orb Ability: Swift Swim - Swords Dance - Aqua Jet - Waterfall - Stone Edge Qwilfish @ Life Orb Ability: Swift Swim - Swords Dance - Poison Jab - Waterfall - Explosion Electrode @ Damp Rock Ability: Soundproof - Thunder - Rain Dance - Taunt - Explosion