0% found this document useful (0 votes)
25 views20 pages

Practical-3:: Practical 3.1 AIM: Installing Anaconda On Windows. 1

The document discusses installing and using Anaconda and Jupyter Notebook on Windows. It covers downloading and running the Anaconda installer, creating and opening Jupyter notebooks, and performing common tasks like creating different cell types and editing cells.

Uploaded by

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

Practical-3:: Practical 3.1 AIM: Installing Anaconda On Windows. 1

The document discusses installing and using Anaconda and Jupyter Notebook on Windows. It covers downloading and running the Anaconda installer, creating and opening Jupyter notebooks, and performing common tasks like creating different cell types and editing cells.

Uploaded by

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

EN: -211230107011

PRACTICAL-3
Practical 3.1:-
AIM: Installing Anaconda on Windows.

1. Visit the Anaconda downloads page


Go to the following link: Anaconda.com/downloads

The Anaconda Downloads Page will look something like this:

2. Select Windows

Select Windows where the three operating systems are listed.

3. Download
Download the most recent Python 3 release. At the time of writing, the most recent release
was the Python 3.6 Version. Python 2.7 is legacy Python. For problem solvers, select the
Python 3.6 version. If you are unsure if your computer is running a 64-bit or 32-bit
version of Windows, select 64-bit as 64-bit Windows is most common.

Python for Data


EN: -211230107011

The download is quite large (over 500 MB) so it may take a while to
forAnaconda to download.

4. Open and run the installer


Once the download completes, open and run the .exe installer

At the beginning of the install, you need to click Next to confirm


the installation.

Then agree to the license.

Python for Data


EN: -211230107011
At the Advanced Installation Options screen, I recommend that you do notcheck
"Add Anaconda to my PATH environment variable"

Click on install.

Python for Data


EN: -211230107011

Practical 3.2: -
AIM: Working with Jupyter Notebook.
 Creating a New Notebook

Open the Jupyter Notebook(anaconda3) from the Windows start menu

After the installation of Anaconda is complete, you can go to the Windows startmenu and
select the Jupyter Notebook.

After Opening Jupyter Notebook Click on New button at right top of the screenand select
Python 3.

Python for Data


EN: -211230107011

 Opening existing notebooks.

To open existing notebooks select the notebook file on home screen ofthe Jupyter
notebook.

(Example: here I am selecting Untitled.ipynb)

After selecting that file the notebook file will be opened.

Python for Data


EN: -211230107011

 Using Google Drive for existing notebooks.

Google Drive is the default location for many operations in Colab, and you can
always choose it as a destination. When working with Drive, yousee a list of
files similar to those shown in Figure. Toopen a particular file, you click its link
in the dialog box. The file opens in the current tab of your browser.

 Using GitHub for existing notebooks

When working with GitHub, you initially need to provide the location ofthe source
code online, as shown in Figure. The location must point to apublic project; you
can’t use Colab to access private projects.

Python for Data


EN: -211230107011

 Using local storage for existing notebooks

If you want to use the downloadable source for this book, or any local source for
that matter, you select the Upload tab of the dialog box. In thecenter is a single
button, Choose File. Clicking this button opens the FileOpen dialog box for your
browser.
You locate the file you want to upload, just as you normally would for opening
any file.

 Using Drive to save notebooks

The default location for storing your data is Google Drive. When you choose File ⇒
Save, the content you create goes to the root directory of your Google Drive. If you
want to save the content to a different folder, you need to select that folder in
Google Drive (https://drive.google.com/).

 Using GitHub to save notebooks

GitHub provides an alternative to Google Drive for saving content. It offers


an organized method of sharing code for the purpose of discussion,review,
and distribution. You can find GitHub at https://github.com/.

Python for Data


EN: -211230107011

Practical 3.3: -
AIM:Performing Common Tasks

 Creating code cells

The first cell that Colab creates for you is a code cell. The code you create in Colab
uses all the same features that you find in Notebook. However, off to the side of
the cell, you see a menu of extras that you canuse with Colab that aren’t present in
Notebook, as shown in Figure.

You use the options shown in Figure to augment your Colab


code experience. The following list

 provides a short description of these features:

Link to Cell: Displays a dialog box containing a link you can use to access a
specific cell within the notebook. You can embed this link anywhere on a web page
or within a notebook to allow someone to accessthat specific cell. The person still
sees the entire notebook but doesn’t have to search for the cell you want to discuss.

Delete Cell: Removes the cell from the notebook.

Clear Output: Removes the output from the cell. You must run the codeagain to
regenerate the output. View Output Fullscreen: Displays the output (not the entire
cell or any other part of the notebook) in full-screenmode on the host device. This
option is useful when displaying a significant amount of content or when a
detailed view of graphics helps explain a topic. Press Esc to exit full-screen mode.

Python for Data


EN: -211230107011

Add a Comment: Creates a comment balloon to the right of the cell. This is not
the same as a code omment, which exists in line with the codebut affects the entire
cell. You can edit, delete, or resolve comments. A resolved comment is one that
receives attention and is no longer applica-ble.

Add a Form: Inserts a form into the cell to the right of the code. You useforms to
provide a graphical input for parameters. Forms don’t appear in Notebook, but
because of how you create them, they won’t prevent you from running the code
in Notebook. You can read more about forms at
https://colab.research.google.com/notebooks/forms.ipynb.

Code cells also tell you about the code and its execution. The little icon next to the
output displays information about the execution when you hover your mouse over it,
as shown in Figure. Clicking the icon clears theoutput. You must run the code again
to regenerate the output.

 Creating text cells

Text cells work much like Markup cells in Notebook. However, Figure shows that
you receive additional help in formatting the text using a graphical interface. The
markup is the same, but you have the option of allowing the GUI to help you create
the markup. For example, in this case, to create the # sign for a heading, you click
the double T icon that appears first in the list. Clicking the double T icon again
would increasethe header level. To the right, you see how the text will appear in
the notebook.

Python for Data


EN: -211230107011

Notice the menu to the right of the text cell. This menu contains many ofthe
same options that a code cell does. For example, you can create a listof links to
help people access specific parts of your notebook through anindex. Unlike
Notebook, you can’t execute text cells to resolve the markup they contain.

 Creating special cells

The special cells that Colab provides are variations of the text cell. Thesespecial
cells, which you access using the Insert menu option, make creating the
required cells faster. The following sections describe each ofthese special cell
types.

 Working with headings

When you choose Insert ⇒ Section Header Cell, you see a new
cellcreated below the currently selected

cell that has the appropriate header level 1 entry in it. You can increasethe
heading level by clicking

the double T icon. The GUI looks the same as the one in Figure 4-11, soyou have
all the standard

formatting features for your text.

Python for Data


EN: -211230107011

 Working with table of contents

An interesting addition to Colab is the automatic generation of a table of contents for


your notebook. To use this feature, choose Insert ⇒ Table ofContents Cell. Figure
shows the output for this particular example.

The Table of Contents cell contains a heading in the actual cell that youcan modify
in the same way as any other heading in your notebook. Thetable of contents
appears in the cell output. To update the table of contents, click Refresh to the
right of the cell output. You also have access to all the usual text cell features
when working with a Table of Contents cell.

 Editing cells

Both Colab and Notebook have Edit menus that contain the options you except,
such as the ability to cut, copy, and paste cells. The two productshave some
interesting differences. For example, Notebook allows you tosplit and merge cells.
Colab contains an option to show or hide the code as a toggle. These differences
give each product a slightly different flavor but don’t really change your ability to
use it to create and modify Python code.

 Moving cells

The same technique you use for moving cells in Notebook also workswith
Colab. The only difference is that Colab relies exclusively on

Python for Data


EN: -211230107011

toolbar buttons, while Notebook also has cell movement options on theEdit menu.

 Executing the Code

For your to be useful, you need to run it at some point. Previous sections have
mentioned the right-pointing arrow that appears in the current cell. Clicking it
runs just the current cell. Of course, you have other options than clicking the right-
pointing arrow, and all these options appear on theRuntime menu.

The following list summarizes these options:

Running the current cell: Besides clicking the right-pointing arrow,you can
also choose Runtime⇒ Run the Focused Cell to execute the code in the
current cell.

Running other cells: Colab provides options on the Runtime menu


forexecuting the code in the next cell, the previous cell, or a selection of cells.
Simply choose the option that matches the cell or set of cells youwant to
execute.

Running all the cells: In some cases, you want to execute all the code ina notebook.
In this case,choose Runtime ⇒ Run All. Execution starts at the top of the notebook,
in the first cell containing code, and continues tothe last cell that contains code in
the notebook. You can stop execution atany time by choosing Runtime ⇒ Interrupt
Execution.

Python for Data


EN: -211230107011

Practical 3.3 : -
AIM: Defining the code repository

 Defining a new folder

You use folders to hold your code files for a particular project. Theproject for
this book is Rohit. The following steps help you create a new folder for this
book.

1. Choose New ⇒ Folder.


Notebook creates a new folder for you. The name of the folder can vary,
but for Windows users, it’s simply listed as Untitled Folder. You may have
to scroll down the list of available folders to find thefolder in question.

2. Place a check in the box next to Untitled Folder.

3. Click Rename at the top of the page.

You see the Rename Directory dialog box, shown in Figure 3-6.

4. Type Folder name and press Enter.

Notebook renames the folder for you.

 Creating a new notebook

Python for Data


EN: -211230107011
Every new notebook is like a file folder. You can place individual ex- amples
within the file folder, just as you would sheets of paper into a physical file folder.
Each example appears in a cell. You can put other sorts of things in the file folder,
too, but you see how these things workas the book progresses. Use these steps to
create a new notebook.

1. Click the Folder name entry on the Home page.


You see the contents of the project folder for this book, which will beblank
if you’re performing this exercise from scratch.

2. Choose New ⇒ Python 3.


You see a new tab open in the browser with the new notebook, as shownin Figure.
Notice that the notebook contains a cell and that Notebook hashighlighted the cell
so that you can begin typing code in it. The title of the notebook is Untitled right
now. That’s not a particularly helpful title,so you need to change it.

3. Click Untitled on the page.

Notebook asks whether you want to use a new name, as shown in Figure.

4. Type Filename and press Enter.

Python for Data


EN: -211230107011

 Adding notebook content

This book follows a convention of putting the source code files together
that makes them easy to use. The following steps tell youabout this
convention:

1. Choose Markdown from the drop-down list that


currentlycontains the word Code.

A Markdown cell contains documentation text. You can put anythingin a


Markdown cell because Notebook won’t interpret it. By using Markdown
cells, you can easily document precisely what you mean when writing code.

2. Type # Downloading the Datasets and Example Code and clickRun


(the button with the right-pointing arrow on the toolbar).

The hash mark (#) creates a heading. A single # creates a first-level heading.
The text that follows contains that actual heading information. Clicking Run
turns the formatted text into a heading, asshown in Figure. Notice that Notebook
automatically creates a new cell for you to use.

3. Choose Markdown, type ## Defining the code repository, andclick Run.

Notebook creates a second-level heading, which looks smaller than afirst-


level heading.

4. Choose Markdown, type ### Adding notebook content, andclick Run.

Notebook creates a third-level heading. Your headings now match


thehierarchy that starts with the first-level heading for this section. Usingthis
approach helps you to easily locate a particular piece of code in the
downloadable source. As always, Notebook creates a new cell for you, and the
cell type automatically changes to Code, so you’re readyto type some code for
this example.

5. Type print(’Python is really cool!’) and click Run.


Notice that the code is color coded so that you can tell the differentbetween
a function (print) and its associated data (’Python is really
cool!’). You see the output shown in Figure. The output is part of the

Python for Data


EN: -211230107011
`
same cell as the code. However, Notebook visually separates
the output from the code so that you can tell them apart.
Notebook automatically creates a new cell for you.

 Exporting a notebook

It isn’t much fun to create notebooks and keep them all to yourself. Atsome
point, you want to share them with other people. To perform this task, you must
export your notebook from the repository to a file. You can then send the file to
someone else who will import it into his or her repository.The previous section
shows how to create a notebook named Sample. You can open this notebook by
clicking its entry in the repository list. The file reopens so that you can see your
code again. To export this code, choose File ⇒ Download As ⇒ Notebook
(.ipynb). What you see next depends on your browser, but you generally see
some sort of dialog box for saving the notebook as a file. Use the same method
for saving the Notebook file as you use for any other file you save using your
browser.

 Removing Notebook

Sometimes notebooks get outdated or you simply don’t need to workwith


them any longer. Rather than allow your repository to get
clogged with files you don’t need, you can remove these
unwantednotebooks from the list. Notice the check box next to the
Sample.ipynb entry in Figure. Use these steps to remove the file:

1. Select the check box next to the Sample.ipynb entry.

2. Click the Delete (trashcan) icon.


You see a Delete notebook warning message like the one shown inFigure.

Python for Data


EN: -211230107011

3. Click Delete.

Notebook removes the notebook file from the list.

 Importing Notebook

To use the source code from this book, you must import the downloaded files
into your repository. The source code comes in an archive file that you extract
to a location on your hard drive. The archive contains a list of .ipynb (IPython
Notebook) files containing the source code. The following steps tell how to
import thes files intoyour repository:

1. Click Upload on the Notebook Rohit page.


What you see depends on your browser. In most cases, you see sometype of
File Upload dialog box that provides access to the files on your hard drive.

2. Navigate to the directory containing the files you want


toimport into Notebook.

3. Highlight one or more files to import and click the Open


(orother, similar) button to begin the upload process.

You see the file added to an upload list, as shown in Figure. The file isn’t part of the
repository yet — you’ve simply selected it for upload.

4. Click Upload.

Notebook places the file in the repository so that you can begin usingit.

Python for Data


EN: -211230107011

Python for Data


EN: -211230107011

Practical 3.4:-
AIM: Understanding the following datasets with its code.
This book uses a number of datasets, all of which appear in the Scikit-learn library. These
dataset demonstrate various ways in which you can interact with data, and you use them in
the examples to perform a variety of tasks. The following list provides a quick overview of
the function used to import each of the datasets into your Python code:

 load_boston(): Regression analysis with the Boston house-pricesdataset

Load and return the boston house-prices dataset (regression).

 load_iris(): Classification with the Iris dataset

Load and return the iris dataset (classification).The iris dataset is a classic
and very easy multi-class classification dataset.

 load_diabetes(): Regression with the diabetes dataset

Load and return the diabetes dataset (regression).

 load_digits([n_class]): Classification with the digits dataset

Load and return the digits dataset


(classification). Each datapoint is a 8x8 image of
a digit.

Python for Data


EN: -211230107011

 fetch_20newsgroups(subset=’train’): Data from 20 newsgroups

Load the filenames and data from the 20 newsgroups dataset


(classification). Download it if necessary.

 fetch_olivetti_faces(): Olivetti faces dataset from AT&T

Load the Olivetti faces data-set from AT&T


(classification). Download it if necessary.

Python for Data

You might also like