Posts

Showing posts with the label Python

Teaching Computers to Play Tic Tac Toe: A Reinforcement Learning Approach

Image
 You can see the full code on GitHub: https://github.com/SQLNoggin/Smart-TicTacToe-RL_NaomiA.git This Python script implements a reinforcement learning agent to play the game of Tic Tac Toe. The agent is trained through Q-learning, a type of model-free reinforcement learning that uses a Q-table to estimate the value of taking specific actions in particular states. Let's break down the key aspects:   Overview The script uses the Tkinter library to create a graphical user interface (GUI) where the Tic Tac Toe game can be played. NumPy is used for numerical operations, and the pickle library is used to save and load the Q-table to/from a file. Constant and Hyperparameter Definitions PLAYER_X and PLAYER_O : Constants representing the two players (1 for X and -1 for O). EMPTY : Constant representing an empty cell on the Tic Tac Toe board. ALPHA : The learning rate used in the Q-learning updates. GAMMA : The discount factor used in the Q-learning updates. EPSILON_START, EPSILON_END,...

How to Create a Neural Network for Recognizing Hand-Drawn Shapes

Image
  by Naomi A. In this guide, we will walk through the process of developing a neural network that identifies hand-drawn shapes. The tutorial is broken down into three main sections: Preprocessing the hand-drawn shapes. Training a neural network to recognize these shapes. Creating a simple user interface to predict the drawn shapes.   All code is available on github under the MIT License. (LINK TO REPO)  1. MNIST Maker: Preprocessing Hand-Drawn Shapes Objective : Convert the images of hand-drawn shapes into a standardized format for machine learning. Steps: Load the images from a specified directory. Convert them to grayscale and resize them to 28x28 pixels. Normalize the pixel values. Label the images based on their filenames. Shuffle and split the data for training, validation, and testing.  SCRIPT for creating the MNIST Dataset: import cv2 import numpy as np import os import random # Path to the shapes directory base_folder = r"C:\yourpathgoeshere" shapes...

Run Queries in SQL Server Using Python!

Image
By Naomi A. This is a fairly quick one - all of the info needed on how the script works is in the comments! The full script is ready for download on GitHub: (LINK) # Import the pyodbc module. #This module allows Python to connect to an ODBC database, like SQL Server. import pyodbc # The variables hold the server name, database name, username, and password. # This is necessary in order to connect to the SQL Server database. server = 'ServerName' database = 'DBName' username = 'user' password = 'password' # Connection string: # This is a formatted string that the ODBC driver uses to know who is connecting (username and password), # where they are connecting to (server and database), # and what driver they are using to make the connection (ODBC Driver 17 for SQL Server). connection_string = f 'DRIVER= {{ ODBC Driver 17 for SQL Server }} ;SERVER= { server } ;DATABASE= { database } ;UID= { username } ;PWD= { password } ' # DRIVER={{ODBC Dri...

Python in a Flash: Learn the Basics in Just 5 Minutes!

Image
  Python is a high-level, interpreted programming language that is widely used in various fields such as data science, web development, and artificial intelligence. It has a clean and simple syntax, making it easy to read and write code in Python. To get started with Python, you'll need to install it on your computer. Python can be downloaded for free from the official website, python.org .    Once you have Python installed, you can start writing Python code using any text editor, such as Notepad, Sublime Text, or Atom. Python code is executed line-by-line, and you can use the print() function to display output to the screen.    Example:   This code will display the text "Hello, World!" on the screen. Python supports many different data types, such as strings, integers, floats, and booleans.    Examples:   This code will display the text "Hello World" on the screen. Python also has built-in control flow statements, such as if/else statements ...

Pythonic Cheat Sheet: A Poem for Programmers by Naomi A.

Image
 Pythonic Cheat Sheet: A Poem for Programmers   Pythonic Cheat Sheet: A Poem for Programmers by Naomi A. With Naomi's cheat sheet, you won't be lost, you can use this at no cost!  Here are some functions you should know,  To help you code and make programs flow: First, there's the print() function,  To output your text without destruction.  Then, input() gets user data in,  A handy function, where to begin. Type conversion, with int() and str(),  To change data types, without a blur.  Also, len() measures length with ease,  For strings, lists, and more, it's a breeze. Math functions like round() and pow(),  To handle numbers, no need to row.  Max() and min() find the extremes,  For a list or data, it's just a dream. Want to sort your data? sorted() is your friend,  To organize your lists, beginning to end.  Slice your data, with [start:end],  A quick way to work on a chunk, my friend. Lastly, join() and spli...

Understanding How Python Syntax Works: Basic Concepts Explained

Image
By Naomi A. Python is a popular programming language known for its user-friendly and intuitive syntax. This article aims to introduce the fundamental concepts of Python syntax, including comments, variables, data types, and control structures, to beginners. Comments: Are an essential aspect of code documentation that helps programmers to understand the code's purpose. In Python, comments are indicated using the hash symbol (#).  Here's an example: Variables: Are used to store values, such as integers, floating-point numbers, and strings. To assign a value to a variable, use the equal sign (=). Here are some examples: Data types : Refer to the various kinds of values that can be stored in a variable. Python supports several data types, including integers, floats, strings, lists, tuples, and dictionaries. Here's an example:   Control structures: Such as conditional statements and loops, are used to control the flow of code execution. Conditional statements are used t...