al ml python
al ml python
CHAPTER 1
ABOUT THE ORGANIZATION
CHAPTER 2
INTRODUCTION TO AL & ML WITH PYTHON
2.1 Definition
Machine Learning : Machine learning is a type of artificial intelligence (AI) that provides
computers with the ability to learn without being explicitly programmed. Machine learning
focuses on the development of Computer Programs that can change when exposed to new
data. In this article, we’ll see basics of Machine Learning, and implementation of a simple
machine-learning algorithm using python.
Machine learning is a method of teaching computers to learn from data, without being
explicitly programmed. Python is a popular programming language for machine learning
because it has a large number of powerful libraries and frameworks that make it easy to
implement machine learning algorithms.
To get started with machine learning using Python, you will need to have a basic
understanding of Python programming and some knowledge of mathematical concepts such
as probability, statistics, and linear algebra.
There are several libraries and frameworks in Python that can be used for machine learning,
including:
scikit-learn: This library provides a wide range of machine learning algorithms, including
supervised and unsupervised learning, and it is built on top of other libraries such as NumPy
and SciPy.
TensorFlow: This library is an open-source machine learning framework developed by
Google, it is widely used for deep learning and other complex machine learning tasks.
Keras: A high-level neural networks API, written in Python and capable of running on top
of TensorFlow, CNTK, or Theano.
PyTorch: An open-source machine learning library for Python, based on Torch library. It
provides a seamless integration of computation graph and PyTorch tensors.
Theano: A numerical computation library for Python that allows you to efficiently define,
optimize, and evaluate mathematical expressions involving multi-dimensional arrays.
Pandas: A library that provides fast and flexible data structures and data analysis tools for
the Python programming language.
A better option would be downloading miniconda or anaconda packages for python, which
come prebundled with these packages. Follow the instructions given here to use anaconda.
Machine learning involves a computer to be trained using a given data set, and use
this training to predict the properties of a given new data. For example, we can train a
computer by feeding it 1000 images of cats and 1000 more images which are not of a cat,
and tell each time to the computer whether a picture is cat or not. Then if we show the
computer a new image, then from the above training, the computer should be able to tell
whether this new image is a cat or not.
The process of training and prediction involves the use of specialized algorithms. We feed
the training data to an algorithm, and the algorithm uses this training data to give predictions
on a new test data. One such algorithm is K-Nearest-Neighbor classification (KNN
classification). It takes a test data, and finds k nearest data values to this data from test data
set. Then it selects the neighbor of maximum frequency and gives its properties as the
prediction result. For example if the training set is:
petal_size flower_type
1 a
2 b
1 a
2 b
3 c
4 d
3 c
2 b
5 a
Now we want to predict flower type for petal of size 2.5 cm. So if we decide no. of neighbors
(K)=3, we see that the 3 nearest neighbors of 2.5 are 1, 2 and 3. Their frequencies are 2, 3
and 2 respectively. Therefore the neighbor of maximum frequency is 2 and flower type
corresponding to it is b. So for a petal of size 2.5, the prediction will be flower type b.
Here is a python script which demonstrates knn classification algorithm. Here we use the
famous iris flower dataset to train the computer, and then give a new value to the computer
to make predictions about it. The data set consists of 50 samples from each of three species
of Iris (Iris setosa, Iris virginica and Iris versicolor). Four features are measured from each
sample: The length and Width of Sepals & Petals, in centimeters.
We train our program using this dataset, and then use this training to predict species of a iris
flower with given measurements.
EX: 1
iris_dataset=load_iris()
kn = KNeighborsClassifier(n_neighbors=1)
kn.fit(X_train, y_train)
Output:
Predicted target name: [0]
Predicted feature name: ['setosa']
Test score: 0.97
CHAPTER 3
ASSIGNMENTS
Output:
Output :
Output :
Output:
CHAPTER 4
REFLECTION
4.1 Weatheraui.py :
import requests
apikey="2bd7c775ee9ce7b80a2712abcdd5361b"
import joblib
import numpy as np
def fetch_weather(cityname):
url=f"https://api.openweathermap.org/data/2.5/weather?q={cityname}&appid={
apikey}"
print(response)
if response.status_code==200:
print("Done successfull")
# print( response.json() )
x=result['main']
temp=x['temp']-273.15
pressure=x['pressure']
humidity=x['humidity']
testdata=np.array([[temp,humidity]])
pred=model.predict(testdata)
else:
msg="Some thing went wrong !"
return msg
4.2 Weathergui.py :
import tkinter as tk
def fetchinfo():
print("you clicked")
cityname=strt1.get()
result=fetch_weather(cityname)
showinfo("wether report",result)
window.title("Weather App")
t1=tk.Entry(window,textvariable=strt1).place(x=150,y=100)#textvariable-
>property, strt1->value, entry used to get value when we click on window
b1=tk.Button(window,text="Fetch weather
info",command=fetchinfo).place(x=280,y=100)#command will define the class and
used chick tyhe button then fetch the info by fetch weather info
4.3 App.py
#import app1
#print(f"value of __name__ in app.py is : {__name__}")
model=joblib.load("knnmodel.pkl")
app=Flask(__name__)
@app.route('/')
def index():
return render_template('cropform.html')
@app.route('/predict',methods=['GET','POST'])
def prediction():
print(testdata)
td=np.array([testdata])
pred=model.predict(td)
return render_template('cropform.html',res=result)
if __name__=='__main__':
app.run(debug=True)
output :
Conclusion
Python’s dominance in AI and Machine Learning is no accident. Its ease of use, versatility, and
vast ecosystem of powerful libraries and frameworks make it the ideal language for building
intelligent systems. Whether it’s computer vision, natural language processing, or predictive
analytics, Python enables developers to turn complex algorithms into practical solutions.
As the field of AI and Machine Learning continues to evolve, Python will undoubtedly remain
at the forefront of innovation. If you aspire to make an impact in these cutting-edge
technologies, mastering Python is a crucial step in your journey. So, whether you’re a seasoned
developer or just stepping into the realm of AI and Machine Learning, Python is your ultimate
companion for shaping the future through innovation and intelligent technology.
In a world where data is the new currency and intelligence is the driving force, Python stands
as the bridge that transforms raw information into actionable insights. As you embark on your
AI and Machine Learning endeavours, remember that Python is not just a programming
language; it’s a gateway to unlocking the potential of artificial intelligence and reshaping the
landscape of innovation. So, seize the opportunity, harness the power of Python, and join the
revolution of building intelligent systems that redefine what’s possible.
Bibliography
3. Tom M. Mitchell, Machine Learning, India Edition 2013, McGraw Hill Educa- tion.
4. Kagglehttps://www.kaggle.com/notebook
5. www.sumukhainfotech.com