0% found this document useful (0 votes)
13 views14 pages

Artificial Intelligence With Python

Uploaded by

hemaparvathi143
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
13 views14 pages

Artificial Intelligence With Python

Uploaded by

hemaparvathi143
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 14

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.

The journey begins with an exploration of the fundamental concepts underlying


AI, including machine learning, deep learning, natural language processing, and
computer vision. The abstract delves into how Python, with its simplicity,
versatility, and rich ecosystem of libraries, has become the language of choice
for AI practitioners and researchers.

The abstract highlights key Python libraries and frameworks such as


TensorFlow, PyTorch, and scikit-learn, illustrating their roles in implementing
various AI algorithms and models. Practical examples demonstrate how Python
facilitates the training and deployment of machine learning models, enabling
users to solve complex problems in diverse domains.

Furthermore, the abstract addresses the role of Python in developing AI-driven


applications, emphasizing its significance in creating intelligent chatbots,
recommendation systems, and image recognition applications. It explores the
seamless integration of Python with popular web frameworks, facilitating the
deployment of AI solutions in real-world scenarios.

Ethical considerations and responsible AI practices are paramount, and the


abstract touches upon how Python, with its emphasis on readability and
transparency, aligns with ethical AI development. It also discusses the
importance of interpretability in AI models and how Python aids in creating
explainable and understandable solutions.

In conclusion, this abstract encapsulates the symbiotic relationship between


Artificial Intelligence and Python, illustrating how Python's simplicity, robust
libraries, and community support make it an ideal language for developing
intelligent systems. As AI continues to evolve, the Python programming
language stands as a powerful tool, empowering developers and researchers to
unlock the full potential of artificial intelligence.

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.

This introduction provides a glimpse into the symbiotic relationship between


Artificial Intelligence and Python, elucidating how Python's simplicity,
extensive libraries, and robust frameworks have positioned it as the language of
choice for AI practitioners. The journey through this exploration begins by
unraveling the fundamental concepts that constitute AI and its diverse
applications. From machine learning and deep learning to natural language
processing and computer vision, Python serves as the common thread weaving
through these intricate domains.

Python's prominence in the AI landscape is not merely coincidental but rather a


result of its ability to seamlessly integrate with cutting-edge AI libraries and
frameworks. TensorFlow, PyTorch, and scikit-learn are just a few examples of
the powerful tools that leverage Python's syntax and functionality to enable the
development of sophisticated AI models. This introduction highlights the
practical aspects of utilizing Python for AI, showcasing how it empowers
developers to train, validate, and deploy machine learning models with relative
ease.

Moreover, the discussion extends beyond the realm of model development,


shedding light on Python's role in crafting AI-driven applications. From
intelligent chatbots to recommendation systems and image recognition, Python's
adaptability and efficiency play a pivotal role in transforming theoretical AI
concepts into tangible solutions. The integration of Python with popular web
frameworks further facilitates the deployment of AI applications in real-world
scenarios, bridging the gap between theory and practical implementation.

As we navigate the landscape of AI, ethical considerations and responsible


development practices come to the forefront. Python's emphasis on readability
and transparency aligns seamlessly with the principles of ethical AI, and this
introduction touches upon the importance of creating interpretable and
understandable AI models.

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

AFTER THIS STEP LET’S TAKE A LOOK AT THE y_test

y_test=array([9, 2, 1, ..., 8, 1, 5], dtype=uint8)

Therefore we have the exact integer values

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"
]

LETS CHECK WHETHER THE ARRAY AS IMPLIMENTED OR NOT

class_names[y_train[0]]
OUTPUT:
'Ankle boot'

AS THE ARRAY IS IMPLEMENTED LETS GET TO THE OTHER STEPS

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'))

AFTER RUNNING THE ABOVE CODE FOR CHECKING THE


ACTIATION LAYERS
SNN.summary()

OUTPUT:
Model: "sequential"
________________________________________________________________
_
Layer (type) Output Shape Param #
=========================================================
========
flatten (Flatten) (None, 784) 0

dense (Dense) (None, 300) 235500

dense_1 (Dense) (None, 100) 30100

dense_2 (Dense) (None, 10) 1010

=========================================================
========
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

1875/1875 [==============================] - 22s 7ms/step - loss:


0.6866 - accuracy: 0.7726

Epoch 2/30

1875/1875 [==============================] - 17s 9ms/step - loss:


0.4763 - accuracy: 0.8349

Epoch 3/30

1875/1875 [==============================] - 15s 8ms/step - loss:


0.4343 - accuracy: 0.8489

Epoch 4/30

1875/1875 [==============================] - 16s 9ms/step - loss:


0.4071 - accuracy: 0.8564

Epoch 5/30

1875/1875 [==============================] - 13s 7ms/step - loss:


0.3872 - accuracy: 0.8642

Epoch 6/30

1875/1875 [==============================] - 13s 7ms/step - loss:


0.3710 - accuracy: 0.8694
Epoch 7/30

1875/1875 [==============================] - 14s 7ms/step - loss:


0.3581 - accuracy: 0.8729

Epoch 8/30

1875/1875 [==============================] - 13s 7ms/step - loss:


0.3463 - accuracy: 0.8769

Epoch 9/30

1875/1875 [==============================] - 13s 7ms/step - loss:


0.3363 - accuracy: 0.8802

Epoch 10/30

1875/1875 [==============================] - 14s 7ms/step - loss:


0.3265 - accuracy: 0.8832

Epoch 11/30

1875/1875 [==============================] - 15s 8ms/step - loss:


0.3187 - accuracy: 0.8861

Epoch 12/30

1875/1875 [==============================] - 12s 7ms/step - loss:


0.3101 - accuracy: 0.8894

Epoch 13/30

1875/1875 [==============================] - 12s 7ms/step - loss:


0.3034 - accuracy: 0.8916

Epoch 14/30

1875/1875 [==============================] - 11s 6ms/step - loss:


0.2971 - accuracy: 0.8931

Epoch 15/30

1875/1875 [==============================] - 12s 6ms/step - loss:


0.2910 - accuracy: 0.8959

Epoch 16/30

1875/1875 [==============================] - 13s 7ms/step - loss:


0.2839 - accuracy: 0.8978

Epoch 17/30

1875/1875 [==============================] - 12s 6ms/step - loss:


0.2782 - accuracy: 0.8993

Epoch 18/30
1875/1875 [==============================] - 11s 6ms/step - loss:
0.2732 - accuracy: 0.9012

Epoch 19/30

1875/1875 [==============================] - 12s 6ms/step - loss:


0.2676 - accuracy: 0.9031

Epoch 20/30

1875/1875 [==============================] - 11s 6ms/step - loss:


0.2627 - accuracy: 0.9052

Epoch 21/30

1875/1875 [==============================] - 11s 6ms/step - loss:


0.2572 - accuracy: 0.9075

Epoch 22/30

1875/1875 [==============================] - 11s 6ms/step - loss:


0.2539 - accuracy: 0.9082

Epoch 23/30

1875/1875 [==============================] - 12s 6ms/step - loss:


0.2484 - accuracy: 0.9103

Epoch 24/30

1875/1875 [==============================] - 12s 6ms/step - loss:


0.2445 - accuracy: 0.9121

Epoch 25/30

1875/1875 [==============================] - 11s 6ms/step - loss:


0.2402 - accuracy: 0.9130

Epoch 2/30

1875/1875 [==============================] - 12s 6ms/step - loss:


0.2364 - accuracy: 0.9152

Epoch 27/30

1875/1875 [==============================] - 11s 6ms/step - loss:


0.2330 - accuracy: 0.9155

Epoch 28/30

1875/1875 [==============================] - 12s 6ms/step - loss:


0.2296 - accuracy: 0.9175

Epoch 29/30
1875/1875 [==============================] - 11s 6ms/step - loss:
0.2241 - accuracy: 0.9202

Epoch 30/30

1875/1875 [==============================] - 12s 6ms/step - loss:


0.2212 - accuracy: 0.9195

AS I WAS RETURNED WITH THE HIGHEST ACCURACY OF 91%


THE MODULE WORKS FINE>>>>>
STEP 9:
EVALUATING THE MODULE X_train,y_train

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

 SCREENSHOT OF THE OUTPUT:


CONCLUSION
In the dynamic landscape of Artificial Intelligence, Python has emerged not only as a facilitator but as
a driving force behind the transformative advancements in the field. Through this exploration, we
have witnessed the symbiotic relationship between AI and Python, understanding how the language's
simplicity, versatility, and robust ecosystem have propelled the development of intelligent systems
and applications.

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.

You might also like