0% found this document useful (0 votes)
34 views9 pages

Py 5

The document discusses various Python libraries and frameworks such as SciPy, scikit-learn, TensorFlow, PyTorch, Django, Flask, and BeautifulSoup, highlighting their applications in scientific computing, machine learning, web development, and data parsing. It also emphasizes Python's role in education, its future growth in data science and AI, and ongoing improvements in performance. Overall, it portrays Python as a versatile and enduring programming language with a strong community and extensive resources.

Uploaded by

dahakeatharva26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views9 pages

Py 5

The document discusses various Python libraries and frameworks such as SciPy, scikit-learn, TensorFlow, PyTorch, Django, Flask, and BeautifulSoup, highlighting their applications in scientific computing, machine learning, web development, and data parsing. It also emphasizes Python's role in education, its future growth in data science and AI, and ongoing improvements in performance. Overall, it portrays Python as a versatile and enduring programming language with a strong community and extensive resources.

Uploaded by

dahakeatharva26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1.​ SciPy: SciPy is a library used for scientific and technical computing.

It
builds on NumPy and provides algorithms for optimization, integration,
interpolation, eigenvalue problems, and others.

from scipy import optimize

def f(x):

return x**2 + 5 * np.sin(x)

result = optimize.minimize(f, x0=2)

2.​ print(result)
3.​ scikit-learn: scikit-learn is a machine learning library that provides simple
and efficient tools for data mining and data analysis. It is built on NumPy,
SciPy, and Matplotlib.

from sklearn.datasets import load_iris

from sklearn.model_selection import train_test_split

from sklearn.neighbors import KNeighborsClassifier

iris = load_iris()

X = iris.data

y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)

knn = KNeighborsClassifier(n_neighbors=3)

knn.fit(X_train, y_train)

accuracy = knn.score(X_test, y_test)

4.​ print(f'Accuracy: {accuracy}')


5.​ TensorFlow: TensorFlow is an open-source machine learning framework
developed by Google. It is used for a wide range of tasks but is particularly
well-known for deep learning applications.

import tensorflow as tf

mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()

x_train, x_test = x_train / 255.0, x_test / 255.0

model = tf.keras.models.Sequential([

tf.keras.layers.Flatten(input_shape=(28, 28)),

tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),

tf.keras.layers.Dense(10)

])

model.compile(optimizer='adam',

loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),

metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)

6.​ model.evaluate(x_test, y_test, verbose=2)


7.​ PyTorch: PyTorch is an open-source machine learning library developed by
Facebook's AI Research lab. It is known for its dynamic computation graph
and is widely used for deep learning applications.

import torch

import torch.nn as nn

import torch.optim as optim

class Net(nn.Module):

def __init__(self):
super(Net, self).__init__()

self.fc1 = nn.Linear(28*28, 512)

self.fc2 = nn.Linear(512, 10)

def forward(self, x):

x = torch.flatten(x, 1)

x = torch.relu(self.fc1(x))

x = self.fc2(x)

return x

net = Net()

criterion = nn.CrossEntropyLoss()

optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)

for epoch in range(2):

running_loss = 0.0

for i, data in enumerate(trainloader, 0):

inputs, labels = data

optimizer.zero_grad()
outputs = net(inputs)

loss = criterion(outputs, labels)

loss.backward()

optimizer.step()

running_loss += loss.item()

if i % 2000 == 1999:

print(f'[{epoch + 1}, {i + 1}] loss: {running_loss / 2000}')

running_loss = 0.0

8.​ print('Finished Training')


9.​ Django: Django is a high-level web framework that encourages rapid
development and clean, pragmatic design. It follows the
"batteries-included" philosophy and provides a lot of built-in functionality.

# Django example

from django.http import HttpResponse

from django.urls import path

def home(request):

return HttpResponse("Hello, World!")


urlpatterns = [

path('', home),

10.​]
11.​Flask: Flask is a micro-framework for web development that is easy to learn
and simple to use. It provides the essential tools for building web
applications without the overhead of a larger framework.

# Flask example

from flask import Flask

app = Flask(__name__)

@app.route('/')

def home():

return "Hello, World!"

if __name__ == '__main__':

12.​ app.run(debug=True)

13.​BeautifulSoup: BeautifulSoup is a library for parsing HTML and XML


documents. It creates parse trees that are helpful for extracting data from
HTML.

# Web scraping with BeautifulSoup


import requests

from bs4 import BeautifulSoup

url = 'https://example.com'

response = requests.get(url)

soup = BeautifulSoup(response.text, 'html.parser')

14.​print(soup.title.text)

Python in Education

Python's simplicity and readability make it an ideal language for teaching


programming concepts to beginners. Many educational institutions have adopted
Python as the primary language for introductory programming courses, helping
students develop a strong foundation in programming principles.

1.​ Educational Institutions: Universities and colleges around the world use
Python to teach programming. The language's clear syntax and extensive
standard library make it an excellent choice for introductory courses, as
well as more advanced topics like data science and machine learning.
2.​ Online Learning Platforms: Online learning platforms like Coursera, edX,
and Udacity offer Python courses for learners of all levels. These courses
cover a wide range of topics, from basic programming concepts to
advanced data science and machine learning techniques.
3.​ K-12 Education: Python is also being introduced in K-12 education to
expose students to programming at an early age. Initiatives like Code.org
and the Hour of Code use Python to teach basic programming concepts to
young learners, fostering an interest in computer science and technology.
Python's Future

As Python continues to evolve, its future looks bright. The language's popularity
and versatility make it a strong contender in the ever-changing landscape of
programming languages. Several trends and developments are shaping Python's
future:

1.​ Continued Growth in Data Science and AI: Python's dominance in data
science and AI is expected to continue, with new libraries and frameworks
emerging to support these fields. As data becomes increasingly important
in various industries, Python's role in data analysis and machine learning
will only grow.
2.​ Expansion into New Domains: Python is expanding into new domains,
such as IoT (Internet of Things) and embedded systems. Libraries like
MicroPython enable Python to run on microcontrollers, opening up new
possibilities for embedded programming.
3.​ Improvements in Performance: While Python is known for its simplicity and
readability, it is not the fastest language in terms of performance. Ongoing
efforts to improve Python's performance, such as the development of
just-in-time (JIT) compilers and the use of alternative implementations like
PyPy, aim to address this limitation.
4.​ Community-Driven Innovation: The Python community will continue to
drive innovation, contributing to new libraries, frameworks, and tools that
enhance the language's capabilities. This collaborative spirit will ensure
that Python remains a relevant and powerful language for years to come.

Conclusion

Python has come a long way since its inception in the early 1990s. Its simplicity,
readability, and versatility have made it a popular choice for developers across
various industries. From web development to data science, automation to
scientific computing, Python's applications are vast and diverse. The language's
strong community support and extensive ecosystem of libraries and frameworks
further enhance its appeal.

As Python continues to evolve, its future looks promising. The language's impact
on education, data science, and AI will only grow, solidifying its position as a
leading programming language. Whether you are a beginner taking your first
steps into programming or an experienced developer looking to expand your
skills, Python offers a wealth of opportunities and resources to help you succeed.

In conclusion, Python's combination of simplicity, versatility, and community


support makes it a powerful and enduring language in the world of programming.
Its continued growth and expansion into new domains ensure that Python will
remain a relevant and influential language for years to come.

You might also like