Artificial Intelligence With Python
Artificial Intelligence With Python
NAME: K.KESHAW
COURSE: ARTIFICIAL INTELLIGENCE WITH PYTHON
COURSE COORDINATOR: SONAM DANGI
INSTITUTE: SAI VIDYA INSTITUTE OF
TECHNOLOGY
Abstract:
Artificial Intelligence (AI) has emerged as a transformative technology,
revolutionizing various industries and reshaping the way we approach problem-
solving. This abstract provides a comprehensive overview of the intersection
between Artificial Intelligence and the Python programming language,
showcasing the synergy that has propelled the development of intelligent
systems and applications.
Introduction
Artificial Intelligence (AI) represents a paradigm shift in the way we
conceptualize and approach problem-solving across various domains. As an
interdisciplinary field, AI encompasses a broad spectrum of techniques, ranging
from traditional rule-based systems to advanced machine learning algorithms
and neural networks. At the heart of this technological revolution lies Python, a
versatile and user-friendly programming language that has become synonymous
with AI development.
CODE
NOTE: CODE MUST BE TYPED IN JUPITER NOTEBOOK AND EACH STEP SHOULD HAVE TO HAVE ITS INDUVIDUAL
BLOCK OF CODE FOR BEST RESULTS
STEP 1:
IMPORTING MODULES
import tensorflow as tf
from tensorflow import keras
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
STEP 2:
GETTING DATA FROM KERAS DATASET: i.e. FASHION.MNIST
fashion=keras.datasets.fashion_mnist
(X_train, y_train),(X_test, y_test)= fashion.load_data()
OUTPUT:
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz
29515/29515 [==============================] - 0s 3us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz
26421880/26421880 [==============================] - 27s 1us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz
5148/5148 [==============================] - 0s 0s/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz
4422102/4422102 [==============================] - 4s 1us/step
STEP 3:
VALUES OF THE X_train and X_test are converted into ‘float32’,and
divided by 255 to get exact values i.e. 0’s and 1’s.
X_train=X_train.astype('float32')/255
X_test=X_test.astype('float32')/255
STEP 4:
CREATE AN ARRAY WITH THE LIST OF ELEMENTS
AVAILABLE ON THE FASION.MNIST
class_names = ["T-shirt/top",
"Trouser",
"Pullover",
"Dress",
"Coat",
"Sandal",
"Shirt",
"Sneaker",
"Bag",
"Ankle boot"
]
class_names[y_train[0]]
OUTPUT:
'Ankle boot'
STEP 5:
TO SHOW THE IMAGE THAT THE y_train CONTAINS
plt.imshow(X_train[0],cmap='grey')
class_names[y_train[0]]
OUTPUT:
‘ANKLE BOOT’
STEP 6:
THE MOST IMPORTANT STEP IS TO CRAETE HIDDEN LAYERS
IN THE MODULE
LAYER1-INPUT LAYER
LAYER2-CONNECTING LAYERS
LAYER3-OUTPUT LAYER
SNN=keras.models.Sequential()
SNN.add(keras.layers.Flatten(input_shape=[28,28]))
SNN.add(keras.layers.Dense(300,activation='relu'))
SNN.add(keras.layers.Dense(100,activation='relu'))
SNN.add(keras.layers.Dense(10,activation='softmax'))
OUTPUT:
Model: "sequential"
________________________________________________________________
_
Layer (type) Output Shape Param #
=========================================================
========
flatten (Flatten) (None, 784) 0
=========================================================
========
Total params: 266610 (1.02 MB)
Trainable params: 266610 (1.02 MB)
Non-trainable params: 0 (0.00 Byte)
STEP 7:
THE MODULE IS COMPILED USING LOSS OF SCC i.e. SPARSE
CATEGORICAL CROSSENTROPY
OPTIMIZER=’SGD’
METRICS=’ACCURACY’
NOTE: IF THE ACCURACY RETURNED IS LESS USE OTHER OPTIMIZERS
LIKE ADAM, RMSdrop
SNN.compile(loss="sparse_categorical_crossentropy",optimizer="sgd",metr
ics=["accuracy"])
STEP 8:
THE MODULE VALUES ARE THEN FITTED INTO THE OBJECTS
“HISTORY” CREATED BY USER
history=SNN.fit(X_train,y_train,epochs=30)
OUTPUT:
Epoch 1/30
Epoch 2/30
Epoch 3/30
Epoch 4/30
Epoch 5/30
Epoch 6/30
Epoch 8/30
Epoch 9/30
Epoch 10/30
Epoch 11/30
Epoch 12/30
Epoch 13/30
Epoch 14/30
Epoch 15/30
Epoch 16/30
Epoch 17/30
Epoch 18/30
1875/1875 [==============================] - 11s 6ms/step - loss:
0.2732 - accuracy: 0.9012
Epoch 19/30
Epoch 20/30
Epoch 21/30
Epoch 22/30
Epoch 23/30
Epoch 24/30
Epoch 25/30
Epoch 2/30
Epoch 27/30
Epoch 28/30
Epoch 29/30
1875/1875 [==============================] - 11s 6ms/step - loss:
0.2241 - accuracy: 0.9202
Epoch 30/30
SNN.evaluate(X_train,y_train)
STEP 10:
AS THE MODULE VALUES ARE DECIMALS WE CONERT IT INTO
WHOLE NUMBERS USING THE FUNTION OF NUMPY i.e. argmax()
predict_class=np.argmax(predict_y,axis=1)
OUTPUT:
array([9, 2, 1, ..., 8, 1, 5], dtype=int64)
STEP 11:
FOR INPUT GETTING RANDOM VALUES AND THE OUTPUT IS
ACCURATE OF 91 percentage
from random import randrange
item=randrange(10000)
plt.imshow(X_test[item],cmap='grey')
print("The predicted class is "+ str(class_names[predict_class[item]]))
THE COMPILER PICS A RANDOM ALUE FOR THE ITEM AND SHOWS
THE FASHION ITEM
OUTPUT:
The predicted class is Coat
Python's role in AI extends beyond mere syntax and convenience; it encapsulates the essence of
accessibility, enabling both seasoned professionals and aspiring developers to engage with complex
AI concepts effortlessly. From foundational principles like machine learning to cutting-edge
technologies such as deep learning, Python serves as a common language that unifies diverse
methodologies, making AI development more inclusive and collaborative.
The practical dimension of Python in AI implementation is evident in its seamless integration with
powerful libraries and frameworks. TensorFlow and PyTorch empower developers to design and train
intricate neural networks, while scikit-learn simplifies the application of machine learning algorithms.
This ease of use not only expedites the development process but also encourages experimentation and
innovation, fostering a vibrant AI community.
The versatility of Python is further highlighted in the creation of AI-driven applications. Whether it's
crafting intelligent chatbots, building recommendation systems, or deploying image recognition
solutions, Python's adaptability facilitates the translation of theoretical AI concepts into real-world
applications. The integration of Python with web frameworks extends the reach of these applications,
ensuring their impact in diverse sectors.
Ethical considerations are paramount in the development of AI, and Python's emphasis on readability
and transparency aligns with the principles of responsible AI. The quest for interpretability and
explain ability in AI models finds resonance in Python's design philosophy, addressing the ethical
challenges associated with the deployment of intelligent systems.
As we conclude this exploration, it becomes evident that the synergy between Artificial Intelligence
and Python is not just a technical marriage; it symbolizes a democratization of AI, where the power to
innovate and solve complex problems is placed in the hands of a broad and diverse community.
Python's continued evolution alongside the advancements in AI reaffirms its status as a cornerstone in
the ongoing narrative of intelligent technologies.
In the ever-evolving landscape of technology, the journey of AI using Python is not reaching a
destination but rather opening doors to new possibilities. The story of AI and Python is one of
collaboration, empowerment, and limitless potential, promising an exciting future where the
boundaries of artificial intelligence continue to be pushed, guided by the simplicity and dynamism of
the Python programming language.