0% found this document useful (0 votes)
9 views3 pages

Lab Manual Data Analysis

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)
9 views3 pages

Lab Manual Data Analysis

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/ 3

Lab Manual: Data Analysis and Machine Learning Experiments

Experiment 1: Installing and Exploring Libraries

Problem Statement
To explore the features of NumPy, SciPy, Jupyter, Statsmodels, and Pandas packages and
read data from a text file, Excel file, and the web.

Aim
To familiarize with Python libraries essential for data analysis and scientific computation.

Algorithm

1. Install required libraries using `pip install numpy scipy pandas statsmodels jupyter`.
2. Explore features of each library with basic and advanced examples.
3. Read data from a text file using Pandas.
4. Read data from an Excel file using Pandas.
5. Fetch and analyze data from a web source using Pandas and Requests.

Detailed Sample Program

# Importing libraries
import numpy as np
import pandas as pd
from scipy.stats import ttest_1samp, norm
from scipy.optimize import minimize
import statsmodels.api as sm
import requests

# NumPy Examples
print("NumPy Examples:")
# Create a 1D array and compute basic statistics
arr = np.array([1, 2, 3, 4, 5])
print("Array:", arr)
print("Mean of array:", np.mean(arr))
print("Standard Deviation:", np.std(arr))

# Advanced NumPy: Matrix operations


matrix = np.random.rand(3, 3)
print("
Matrix:")
print(matrix)
print("Matrix Transpose:")
print(matrix.T)
print("Dot Product:")
print(np.dot(matrix, matrix.T))

# SciPy Examples
print("
SciPy Examples:")
# Perform a t-test
print("T-test Example:")
t_stat, p_value = ttest_1samp(arr, 3)
print("T-statistic:", t_stat, "P-value:", p_value)

# Optimization Example
print("
Optimization Example:")
result = minimize(lambda x: x**2 + 5, 0)
print("Optimization Result:", result)

# Pandas Examples
print("
Pandas Examples:")
# Creating a DataFrame
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'Salary': [50000, 60000, 70000]
}
df = pd.DataFrame(data)
print("DataFrame:")
print(df)
print("Summary Statistics:")
print(df.describe())

# Reading data from a text file


print("
Reading from Text File:")
with open('sample.txt', 'w') as f:
f.write("Name,Age,Salary
Alice,25,50000
Bob,30,60000
Charlie,35,70000")
df_text = pd.read_csv('sample.txt')
print(df_text)

# Reading data from an Excel file


print("
Reading from Excel File:")
df.to_excel('sample.xlsx', index=False)
df_excel = pd.read_excel('sample.xlsx')
print(df_excel)

# Reading data from the web


print("
Reading from Web:")
url = 'https://people.sc.fsu.edu/~jburkardt/data/csv/hw_200.csv'
df_web = pd.read_csv(url)
print(df_web.head())

# Statsmodels Example
print("
Statsmodels Example:")
X = sm.add_constant([4, 5, 6])
Y = [1, 2, 3]
model = sm.OLS(Y, X).fit()
print(model.summary())

Enhanced Output
The output includes extensive examples of NumPy functionalities, statistical analysis using
SciPy, comprehensive use of Pandas for data manipulation, and regression analysis with
Statsmodels.

You might also like