








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









NumPy stands for ‘Numerical Python’. It is a package for data analysis and scientific computing with Python. NumPy uses a multidimensional array object, and has functions and tools for working with these arrays. The powerful n-dimensional array in NumPy speeds-up data processing. NumPy can be easily interfaced with other Python packages and provides tools for integrating with other programming languages like C, C++ etc. NumPy is a Python package. It is a library consisting of multidimensional array objects and a collection of routines for processing of array. Numeric, the ancestor of NumPy, was developed by Jim Hugunin. Another package Numarray was also developed, having some additional functionalities. In 2005, Travis Oliphant created NumPy package by incorporating the features of Numarray into Numeric package. Operations using NumPy Using NumPy, a developer can perform the following operations:--
Pandas is an open source, BSD-licensed library. It has high-performance, it is easy-to-use data structures and data analysis tools, built for the Python
disposal of Data Scientists and Analysts working in Python today. The powerful machine learning and glamorous visualization tools may get all the attention, but pandas is the backbone of most data projects. Pandas has so many uses that it might make sense to list the things it can't do instead of what it can do. This tool is essentially your data’s home. Through pandas, you get acquainted with your data by cleaning, transforming, and analyzing it.
from matplotlib import pyplot from pandas import read_csv path = r"C:\pima-indians-diabetes.csv" names = ['preg', 'plas', 'pres', 'skin', 'test','mass','pedi', 'age', 'class'] data = read_csv(path, names=names) data.hist() pyplot.show()
from matplotlib import pyplot from pandas import read_csv path = r"C:\pima-indians-diabetes.csv" names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass','pedi', 'age', 'class'] data = read_csv(path, names=names) data.plot(kind='density', subplots=True, layout=(3,3), sharex=False) pyplot.show()
from matplotlib import pyplot from pandas import read_csv import numpy Path = r"C:\pima-indians-diabetes.csv" names = ['preg', 'plas', 'pres', 'skin', 'test','mass','pedi', 'age', 'class'] data = read_csv(Path, names=names) correlations = data.corr() fig = pyplot.figure() ax = fig.add_subplot(111) cax = ax.matshow(correlations, vmin=-1, vmax=1) fig.colorbar(cax) ticks = numpy.arange(0,9,1) ax.set_xticks(ticks) ax.set_yticks(ticks) ax.set_xticklabels(names) ax.set_yticklabels(names) pyplot.show()
from matplotlib import pyplot from pandas import read_csv from pandas.tools.plotting import scatter_matrix path = r"C:\pima-indians-diabetes.csv" names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass','pedi', 'age', 'class'] data = read_csv(path, names=names) scatter_matrix(data) pyplot.show()
from pandas import read_csv from numpy import set_printoptions from sklearn.preprocessing import Normalizer path = r'C:\pima-indians-diabetes.csv' names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass','pedi', 'age', 'class'] dataframe = read_csv (path, names=names) array = dataframe.values Data_normalizer = Normalizer(norm='l1').fit(array) Data_normalized = Data_normalizer.transform(array)
from pandas import read_csv from numpy import set_printoptions from sklearn. import Normalizer path = r'C:\pima-indians-diabetes.csv' names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class'] dataframe = read_csv (path, names=names) array = dataframe.values Data_normalizer = Normalizer(norm='l2').fit(array) Data_normalized = Data_normalizer.transform(array) set_printoptions(precision=2) print ("\nNormalized data:\n", Data_normalized [0:3])
from sklearn.preprocessing import StandardScaler from pandas import read_csv from numpy import set_printoptions path = r'C:\pima-indians-diabetes.csv’ names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class'] dataframe = read_csv(path, names=names) array = dataframe.values data_scaler = StandardScaler().fit(array) data_rescaled = data_scaler.transform(array) set_printoptions(precision=2) print ("\nRescaled data:\n", data_rescaled [0:5])
import numpy as np from sklearn import preprocessing input_labels = ['red','black','red','green','black','yellow','white'] encoder = preprocessing.LabelEncoder() encoder.fit(input_labels) test_labels = ['green','red','black'] encoded_values = encoder.transform(test_labels) print("\nLabels =", test_labels) print("Encoded values =", list(encoded_values)) encoded_values = [3,0,4,1] decoded_list = encoder.inverse_transform(encoded_values) print("\nEncoded values =", encoded_values) print("\nDecoded labels =", list(decoded_list))