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

Data Analytics Lab Overview

The document outlines an index for a lab file on data analytics submitted by a student named Amit Singh to their professors at NOIDA INSTITUE OF ENGINEERING & TECHNOLOGY, listing topics like performing numerical operations, data import/export, matrix operations, statistical analysis, and simple linear and logistic regression using Python/R. The aims demonstrate how to handle data preprocessing tasks, fit regression models, and evaluate their performance on test data.

Uploaded by

Amit Singh
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)
263 views14 pages

Data Analytics Lab Overview

The document outlines an index for a lab file on data analytics submitted by a student named Amit Singh to their professors at NOIDA INSTITUE OF ENGINEERING & TECHNOLOGY, listing topics like performing numerical operations, data import/export, matrix operations, statistical analysis, and simple linear and logistic regression using Python/R. The aims demonstrate how to handle data preprocessing tasks, fit regression models, and evaluate their performance on test data.

Uploaded by

Amit Singh
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
  • Numerical Operations Using R/Python
  • Data Import/Export Operations
  • Matrix Operations Using R/Python
  • Statistical Operations Using R/Python
  • Data Pre-processing Operations
  • Simple Linear Regression with R/Python
  • Simple Logistic Regression with R/Python

NOIDA INSTITUE OF ENGINEERING & TECHNOLOGY,

GREATER NOIDA

Department of Information Technology

LAB FILE
ON
DATA ANALYTICS LAB
KIT-651
(6th Semester)
(2020 – 2021)

Submitted To: Submitted by:

Ms. Tanya Name: Amit Singh

Dr. Vivek Kumar Roll: 1813313019

Affiliated to Dr. A.P.J Abdul Kalam Technical University, Uttar Pradesh, Lucknow.
Data ANALYTICS LAB
KIT-651
INDEX
[Link] TOPIC DATE GRADE SIGNATURE

To get the input from user and perform numerical


1 operations (MAX, MIN, AVG, SUM, SQRT, ROUND)
using in R/Python.
To perform data import/export (.CSV, .XLS, TXT)
2
operations using data frames in R/Python.
To get the input matrix from user and perform Matrix
addition, subtraction, multiplication, inverse transpose
3
and division operations using vector concept in
R/Python.
To perform statistical operations (Mean, Median, Mode
4
and Standard deviation) using R/Python.
To perform data pre-processing operations i) Handling
5
Missing data ii) Min-Max normalization.
6 To perform Simple Linear Regression with R/Python.

7 To perform Simple Logistic Regression with R/Python.

10

11

12

13

14

15

16
Aim -1. To get the input from user and perform numerical operations (MAX,
MIN, AVG, SUM, SQRT, ROUND) using in R/Python.

import math
list1 = []
  
n = int(input("Enter number of elements : "))
  
for i in range(0, n):
  ele = int(input())
  [Link](ele)
      
print("Sum = ",sum(list1))
print("Maximum element = ",max(list1))
print("Minimum element = ",min(list1))
print("Square root =" ,[Link](list1[1]))
print("Round =",round(5.56))
print("Average = ", sum(list1)/len(list1))

OUTPUT: -
Enter number of elements : 5
1
6
2
8
7
Sum = 24
Maximum element = 8
Minimum element = 1
Square root = 2.449489742783178
Round = 6
Average = 4.8
Aim - 2. To perform data import/export (.CSV, .XLS, TXT) operations using
data frames in R/Python.

from [Link] import drive


[Link]("/content/drive")

import pandas as pd
df = pd.read_csv('/content/drive/MyDrive/Da-Lab/ITUR_rain1.csv')

print([Link])

OUTPUT: -

0 1.0
1 1.5
2 2.0
3 2.5
4 3.0
...
99 96.0
100 97.0
101 98.0
102 99.0
103 100.0
Name: Frequency, Length: 104, dtype: float64
Aim - 3. To get the input matrix from user and perform Matrix addition,
subtraction, multiplication, inverse transpose and division operations using
vector concept in R/Python.

import numpy
r = int(input("Enter  no of row of matrix1 "))
c = int(input("Enter no of cloumns of matrix1 "))
m = []
print("Enter elements")
for i in range(r):          
    a =[]
    for j in range(c):      
         [Link](int(input()))
    [Link](a)
r1 = int(input("Enter the number of rows of matrix 2 "))
c1 = int(input("Enter the number of columns of matrix 2 "))
m1 = []
print("Enter elements")
for i in range(r1):          
    a1 =[]
    for j in range(c1):      
         [Link](int(input()))
    [Link](a1)
m2=[]
for i in range(r):
  a3=[]
  for j in range(c):
    [Link](m[i][j]+m1[i][j])
  [Link](a3)
print("Sum pf matrix is:")
for i in range (r):
  for j in range(c):
    print(m2[i][j],end=" ")
  print()
pm=[]
for i in range (r):
  sm=[]
  for j in range (c):
    s=0
    
    for k in range (c):
      s=s+m[i][k]*m1[k][j]
    [Link](s)
  [Link](sm)
print("Product of matrix:")
for i in range( r):
  for j in range (c):
    print(pm[i][j],end =" ")
  print()
print("Transpose of multiplication matrix is :")
print([Link](pm))

OUTPUT: -

Enter no of row of matrix1 2


Enter no of cloumns of matrix1 2
Enter elements
1
2
3
4
Enter the number of rows of matrix 2 2
Enter the number of columns of matrix 2 2
Enter elements
4
5
6
7
Sum pf matrix is:
57
9 11
Product of matrix:
16 19
36 43
Transpose of multiplication matrix is :
[[16 36]
[19 43]]
Aim -4. To perform statistical operations (Mean, Median, Mode and Standard
deviation) using R/Python.

import statistics as st
lst = []
  

n = int(input("Enter number of elements : "))
  

for i in range(0, n):
    ele = int(input())
  
    [Link](ele) 

print("Mean value is:",[Link](lst))
print("Meadian is:",[Link](lst))
print("Mode value is :",[Link](lst))
print("Standard deviation is :",[Link](lst))

OUTPUT :-

Enter number of elements : 5


1
2
3
4
5
Mean value is: 3
Meadian is: 3
Mode is: 0
Standard deviation is: 1.414
Aim - 5. To perform data pre-processing operations i) Handling Missing data
ii) Min-Max normalization.

import pandas as pd
import numpy as np
df = pd.read_csv("/content/drive/MyDrive/Da-Lab/[Link]")
[Link]()

[Link](['PassengerId','Name','SibSp','Parch','Ticket','Cabin','Embarked'],axis='columns',inplace=
True)
[Link]()
target = [Link]
inputs = [Link]('Survived',axis='columns')

#One-hot encoding
dummies = pd.get_dummies([Link])
[Link](3)

inputs = [Link]([inputs,dummies],axis='columns')
[Link](3)

[Link](['Sex','male'],axis='columns',inplace=True)
[Link](3)
[Link][[Link]().any()]

OUTPUT: -

Index(['Age'], dtype='object')

[Link] = [Link]([Link]())
[Link]()

[Link][:10]

OUTPUT: -

0 22.000000
1 38.000000
2 26.000000
3 35.000000
4 35.000000
5 29.699118
6 54.000000
7 2.000000
8 27.000000
9 14.000000
Name: Age, dtype: float64
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(inputs,target,test_size=0.3)

from sklearn.naive_bayes import GaussianNB
model = GaussianNB()

[Link](X_train,y_train)

OUTPUT: -
GaussianNB(priors=None, var_smoothing=1e-09)

[Link](X_test,y_test)

OUTPUT: -

0.7574626865671642

[Link](X_test[0:10])

OUTPUT: -

array([0, 1, 1, 1, 0, 1, 1, 0, 0, 1])
Aim - 6. To perform Simple Linear Regression with R/Python.

import numpy as np 

import pandas as pd
import [Link] as plt

from [Link] import files
uploaded = [Link]()

data = pd.read_csv("[Link]")
X = [Link](float)

y = [Link](float)

[Link](X,y)
[Link]("Area")
[Link]("Price")
[Link]()
from sklearn import linear_model
from sklearn.linear_model import LinearRegression
reg = linear_model.LinearRegression()
[Link](data[['Area']],[Link])

OUTPUT: -

LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)

[Link]([[100]])

OUTPUT: -

array([9229.8328887])

reg.coef_

OUTPUT: -

array([40.46056658])

reg.intercept_

OUTPUT: -

5183.7762302371

100.6691978*100+1118.140232700558

OUTPUT: -

11185.060012700558
Aim - 7. To perform Simple Logistic Regression with R/Python.

Common questions

Powered by AI

Matrix operations in Python can be performed using libraries like numpy. To input matrices, use nested loops for user input. For matrix addition, iterate through the matrices and sum corresponding elements. For multiplication, use nested loops to compute dot products for new matrix elements. Use numpy.transpose() to transpose matrices effectively.

Challenges in data import/export include incorrect file paths, inconsistent data formatting, and data size limitations. Address these by validating paths, using consistent delimiters, and employing chunking or data compression for large files. Libraries like pandas provide flexible methods for handling these challenges effectively, such as specifying delimiters or using dtypes to enforce consistent data formats.

Matrix transposition in Python can be executed using numpy's transpose function, which switches the row and column indices of a matrix. This operation is crucial in data analysis for aligning data dimensions correctly for operations like matrix multiplication, enabling compatibility and more efficient calculations in linear algebra and machine learning applications.

To calculate the mean, median, mode, and standard deviation in Python, the statistics module can be employed. Use mean(), median(), mode(), and stdev() functions respectively. First, gather the data into a list from user inputs, and then apply these functions to compute and display the required statistics.

Data pre-processing is crucial in machine learning for cleaning and preparing data to improve model accuracy and efficiency. Python, with libraries such as pandas and sklearn, excels in handling missing values, normalizing data, encoding categorical variables, and splitting datasets for training/testing, which is critical for achieving reliable and performance-optimized models.

The sklearn library's LinearRegression() function provides coefficients that represent the slope of the regression line, with intercept representing the y-axis crossing point. From reg.coef_ and reg.intercept_, you can deduce how changes in input (e.g., area) affect the output (e.g., price). Predictive accuracy can be visualized through scatter plots of actual versus predicted values.

Data import/export operations using data frames in Python typically involve using the pandas library. First, import pandas as pd. To load a .CSV file, use pd.read_csv() specifying the file path. This reads the data into a DataFrame object. Similar functions are available for other formats like .XLS and .TXT. This allows for easy manipulation and analysis of tabular data.

To perform numerical operations like maximum, minimum, average, sum, square root, and rounding in Python, you can use built-in functions such as max(), min(), and sum(). For average, divide the sum of the list by its length using len(). For square root, use the sqrt() function from the math module, and for rounding, use round(). These operations can be applied to a list of integers provided by the user through input.

Simple logistic regression in Python involves using sklearn's LogisticRegression. Start by preprocessing data, ensuring it is scaled and categorical variables are encoded. Fit the model with feature data and target classes. Evaluate predictions with model.score() and predicted classes with predict(). The output includes model coefficients reflecting the impact of each feature on the prediction probability.

Handling missing data in Python involves using pandas to fill missing values, e.g., df.fillna() to replace NaN with the mean of the column. For normalization, Min-Max scaling can be applied to scale numerical features to a specified range, often 0 to 1, facilitating better model convergence and performance in machine learning.

Department of Information Technology
LAB FILE
ON
DATA ANALYTICS LAB
KIT-651
(6th Semester)
(2020 – 2021)
Submitted To:
Data ANALYTICS LAB
KIT-651
INDEX
S.NO
TOPIC
DATE
GRADE
SIGNATURE
1
To get the input  from  user and  perform numerical
operat
Aim -1. To get the input from user and perform numerical operations (MAX, 
MIN, AVG, SUM, SQRT, ROUND) using in R/Python.
imp
Aim - 2. To perform data import/export (.CSV, .XLS, TXT) operations using 
data frames in R/Python.
from google.colab import
Aim - 3. To get the input matrix from user and perform Matrix addition, 
subtraction, multiplication, inverse transpose and d
print("Product of matrix:")
for i in range( r):
  for j in range (c):
    print(pm[i][j],end =" ")
  print()
print("Transpose
Aim -4. To perform statistical operations (Mean, Median, Mode and Standard
deviation) using R/Python.
import statistics as st
Aim - 5. To perform data pre-processing operations i) Handling Missing data 
ii) Min-Max normalization.
import pandas as pd
i
target = df.Survived
inputs = df.drop('Survived',axis='columns')
#One-hot encoding
dummies = pd.get_dummies(inputs.Sex)
dummi
inputs.columns[inputs.isna().any()]
OUTPUT: - 
Index(['Age'], dtype='object')
inputs.Age = inputs.Age.fillna(inputs.Age.mean(

You might also like