0% found this document useful (0 votes)
2 views24 pages

Class Xii PDF for Practical

The document provides a comprehensive guide on using Python with NumPy and Pandas for data manipulation and analysis, including creating 2D arrays, accessing elements, performing arithmetic operations, and utilizing DataFrames. It also covers linear regression modeling, handling missing values, and data visualization techniques using the Orange Data Mining tool. Additionally, it discusses the impact of the Mid-Day Meal Scheme on student enrollment and dropout rates, supported by various data visualizations and analyses.

Uploaded by

manthansehgal626
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)
2 views24 pages

Class Xii PDF for Practical

The document provides a comprehensive guide on using Python with NumPy and Pandas for data manipulation and analysis, including creating 2D arrays, accessing elements, performing arithmetic operations, and utilizing DataFrames. It also covers linear regression modeling, handling missing values, and data visualization techniques using the Orange Data Mining tool. Additionally, it discusses the impact of the Mid-Day Meal Scheme on student enrollment and dropout rates, supported by various data visualizations and analyses.

Uploaded by

manthansehgal626
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/ 24

PYTHON PROGAM ON NUMPY

AND DATAFRAME

1. Creating a 2D Array:
import numpy as np

# Create a 2x3 array


arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)

2. Accessing Elements:

import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])

# Access element at row 0, column 1


print(arr[0, 1])

# Access the entire first row


print(arr[0, :])

# Access the entire second column


print(arr[:, 1])

3. Array Arithmetic:

import numpy as np

arr1 = np.array([[1, 2], [3, 4]])


arr2 = np.array([[5, 6], [7, 8]])

# Add two arrays


print(arr1 + arr2)

# Multiply by a scalar
print(arr1 * 2)

# Matrix multiplication
print(np.dot(arr1, arr2))
🛠 Creating 2D Arrays and apply all the functions and
attributes
Import numpy as np

# From a list of lists


a = np.array([[1, 2, 3], [4, 5, 6]])

# Zeros, Ones, and Full

zeros = np.zeros((2, 3))

ones = np.ones((2, 3))

full = np.full((2, 3), 7)

# Random values

rand = np.random.rand(2, 3) # Uniform [0, 1)

randint = np.random.randint(0, 10, (2, 3)) # Random integers

Print(a.T ) # Transpose

b = np.array([[1, 1, 1], [2, 2, 2]])

print(a + b ) # Element-wise addition

print(a – b) # Subtraction

print(a * b) # Element-wise multiplication

print(a / b) # Division

print(a @ b.T ) # Matrix multiplication (dot product)

🔍 Indexing and Slicing


Print(a[0, 1] ) # Element at first row, second column

Print(a[:, 1] ) # All rows, second column

Print(a[1, :]) # Second row, all columns

Print(a[0:2, 1:3]) # Sub-matrix

📊 Aggregation Functions

Print(a.sum()) # Sum of all elements

Print(a.sum(axis=0)) # Sum by columns

Print(a.sum(axis=1)) # Sum by rows

Print(np.mean(a))

Print(np.std(a))

Print(np.max(a))

Print(np.min(a))

Print(np.argmax(a))

Print(np.argmin(a))

🔍 Logical & Filtering

Print(a > 3) # Boolean array

Print(a[a > 3]) # Filter values

Print(np.where(a > 3, 1, 0)) # Conditional replacement)


Pandas DataFrame Programs
1. Creating a DataFrame:

import pandas as pd

# From a dictionary

data = {'Name': ['Alice', 'Bob', 'Charlie'],

'Age': [20, 22, 21],

'City': ['New York', 'London', 'Paris']}

df = pd.DataFrame(data)

print(df)

# From a list of lists

data_list = [[1, 'Alice'], [2, 'Bob'], [3, 'Charlie']]

df_list = pd.DataFrame(data_list, columns=['ID', 'Name'])


print(df_list)

2. Accessing Data:

import pandas as pd

data = {'Name': ['Alice', 'Bob', 'Charlie'],

'Age': [20, 22, 21],

'City': ['New York', 'London', 'Paris']}

df = pd.DataFrame(data)

# Access a single column

print(df['Name'])

# Access multiple columns

print(df[['Name', 'Age']])

# Access a single row

print(df.iloc[0])

# Access a specific element

print(df.loc[0, 'Name'])

3. Data Filtering:
import pandas as pd

data = {'Name': ['Alice', 'Bob', 'Charlie'],

'Age': [20, 22, 21],

'City': ['New York', 'London', 'Paris']}

df = pd.DataFrame(data)

# Filter by age

print(df[df['Age'] > 20])

# Filter by city

print(df[df['City'] == 'London'])

# Multiple conditions

print(df[(df['Age'] > 20) & (df['City'] == 'London')])

🐼 Pandas Basics + Linear Regression in Python

✅ 1. Importing Libraries

import pandas as pd

import numpy as np

from sklearn.linear_model import LinearRegression


from sklearn.model_selection import train_test_split

from sklearn.metrics import mean_squared_error

📥 2. Importing Data from CSV to DataFrame

df = pd.read_csv('data.csv') # Replace 'data.csv' with your file name

print(df.head())

📤 3. Exporting DataFrame to CSV

df.to_csv('output.csv', index=False)

❌ 4. Handling Missing Values

# Detect missing values

print(df.isnull().sum())

# Drop missing values

df_cleaned = df.dropna()

# Fill missing values

df_filled = df.fillna(method='ffill') # Forward fill

df_filled = df.fillna(0) # Fill with 0 or any value

📈 5. Linear Regression with Pandas & scikit-learn

Assume your dataset has a feature column ['X'] and a target column ['Y'].
# Load dataset

df = pd.read_csv('data.csv')

# Drop rows with missing values

df = df.dropna()

# Define X and y

X = df[['X']] # Features (2D array)

y = df['Y'] # Target (1D array)

# Train-test split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,

random_state=42)

# Model training

model = LinearRegression()

model.fit(X_train, y_train)

# Predict

y_pred = model.predict(X_test)

# Evaluate

mse = mean_squared_error(y_test, y_pred)

print("Mean Squared Error:", mse)

print("Coefficient:", model.coef_)

print("Intercept:", model.intercept_)
# linear_regression

import pandas as pd

from sklearn.model_selection import train_test_split

from sklearn.linear_model import LinearRegression

from sklearn.metrics import mean_squared_error

# Sample data

data = {

'X': [1, 2, 3, 4, 5],


'Y': [2, 4, 6, 8, 10]

# Create DataFrame

df = pd.DataFrame(data)

# Split data

X = df[['X']] # Feature

y = df['Y'] # Target

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

# Create and train model

model = LinearRegression()

model.fit(X_train, y_train)

# Predict and evaluate

y_pred = model.predict(X_test)

print("Predictions:", y_pred)

print("Actual:", y_test.values)

print("Mean Squared Error:", mean_squared_error(y_test, y_pred))

print("Coefficient:", model.coef_[0])

print("Intercept:", model.intercept_)
Chatbot Code
# gemini_chatbot.py

import google.generativeai as genai

# Replace with your real API key

genai.configure(api_key="YOUR_GOOGLE_API_KEY")

# Load Gemini model

model = genai.GenerativeModel("gemini-pro")

# Start a chat session

chat = model.start_chat()

# Simple chatbot loop


print("Chatbot: Hello! Ask me anything. Type 'exit' to quit.")

while True:

user_input = input("You: ")

if user_input.lower() in ['exit', 'quit']:

print("Chatbot: Goodbye!")

break

response = chat.send_message(user_input)

print("Chatbot:", response.text)

Python Code to Evaluate a Model.

import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import (
mean_squared_error,
mean_absolute_error,
r2_score
)

# Sample Data
data = {
'X': [1, 2, 3, 4, 5, 6],
'Y': [2.1, 4.0, 5.9, 8.1, 10.2, 12.0]
}

# Load into DataFrame


df = pd.DataFrame(data)

# Features and target


X = df[['X']]
y = df['Y']

# Train-test split
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.33, random_state=42)

# Train model
model = LinearRegression()
model.fit(X_train, y_train)

# Predict
y_pred = model.predict(X_test)

# Evaluate model
mse = mean_squared_error(y_test, y_pred)
mae = mean_absolute_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)

# Display results
print("Predictions:", y_pred)
print("True Values:", y_test.values)
print("Mean Squared Error (MSE):", mse)
print("Mean Absolute Error (MAE):", mae)
print("R² Score:", r2)
print("Coefficient:", model.coef_[0])
print("Intercept:", model.intercept_)
Orange Data
Mining
Here’s a step-by-step guide to help you perform Data Visualization, Classification,
Evaluation, Image Analytics, and Word Cloud tasks using Orange Data Mining Tool.

📌 Since I can't directly provide screenshots, I’ll describe where and what to click so you can
take snapshots easily and paste them into your practical file.

✅ 1. Data Visualization in Orange (Step-wise Procedure)

🔹 Steps:

1. Open Orange Canvas


Launch using the command:
2. orange-canvas

3. Add File Widget


o Drag the File widget to canvas.
o Load a dataset (e.g., iris.tab or .csv).
4. Add Data Table Widget
o Connect File → Data Table.
o View data in table format.
5. Add Box Plot, Distributions, or Scatter Plot Widgets
o Use Box Plot to see distribution by feature.
o Use Scatter Plot to see feature relationships.
6. Connect Widgets
o File → Box Plot
o File → Scatter Plot
o File → Distributions

📸 Take snapshots of:

 Canvas layout
 Opened widgets (Box Plot, Scatter Plot, etc.)
✅ 2. Perform Classification in Orange

🔹 Steps:

1. Drag and Drop:


o File → Load dataset (e.g., iris, titanic)
o Data Table to inspect data
2. Add Preprocessing (optional):
o Select Columns
o Impute (to handle missing values)
3. Add Classifier:
o Add any classifier like:
 Logistic Regression
 Naive Bayes
 Random Forest
 kNN
4. Add Test & Score Widget:
o Connect: File and Classifier → Test & Score

📸 Take snapshots of:

 Canvas with all widgets


 Test & Score output

✅ 3. Evaluate Classification Model

🔹 Steps:

1. Use Test & Score Widget


o Shows metrics like:
 Accuracy
 Precision
 Recall
 F1 Score
 AUC
2. Add Confusion Matrix:
o Connect Test & Score → Confusion Matrix
o Visualize correct vs incorrect classifications

📸 Take snapshots of:

 Test & Score results


 Confusion matrix display
✅ 4. Perform Image Analytics in Orange

🔹 Steps:

1. Install Image Analytics Add-on


In Orange: Options → Add-ons → Image Analytics → Install
2. Widgets to Use:
o Import Images (load folder of images)
o Image Embedding (extract features)
o Image Viewer (view image data)
o t-SNE or PCA (visualize)
3. Optional: Classification
o Connect Image Embedding → Classifier (e.g., SVM)

📸 Snapshots:

 Image viewer with images loaded


 PCA or t-SNE plot
 Classification accuracy (if used)

✅ 5. Visualize Word Frequencies with Word Cloud

🔹 Steps:

1. Drag Corpus Widget


o Load .txt files or predefined text datasets.
2. Connect to Word Cloud:
o Corpus → Word Cloud
3. Optional Enhancements:
o Add Preprocess Text widget (to remove stop words, lowercase, etc.)
o Corpus Viewer to inspect raw text

📸 Snapshots:

 Word cloud display


 Preprocessing settings (if used)

📚 Summary Table for Practical File:


Task Widget Chain Output Screenshot

Data Visualization File → Box Plot, Scatter Plot, Distributions Graph displays

Classification File → Preprocess → Classifier → Test & Score Accuracy metrics

Evaluation Test & Score → Confusion Matrix Confusion matrix


Task Widget Chain Output Screenshot

Image Analytics Import Images → Image Embedding → t-SNE → Image Viewer Image features

Word Cloud Corpus → Preprocess Text → Word Cloud Word frequency cloud

Data
Storytelling

Question :Data Storytelling (Sample) Using available data on student enrollment, attendance, and
dropout rates, create a compelling data story that explores the impact of the Mid-
Day Meal Scheme (MDMS) since its launch in 1995. Uncover trends, patterns, and
correlations in the data to tell a story about how the implementation of the
MDMS may have influenced dropout rates in the state over the years. Consider
incorporating visualizations, charts, and graphs to effectively communicate your
findings. Additionally, analyze any external factors or events that might have
played a role in shaping these trends. Your goal is to provide a comprehensive
narrative that highlights the relationship between the MDMS and student
dropout rates in the state.

📚 Title: Nourishing Futures – How the Mid-Day Meal Scheme Reduced


Dropout Rates in Schools (1995–2024)

🎯 Objective

To explore how the Mid-Day Meal Scheme (MDMS), launched in 1995, influenced student
enrollment, attendance, and dropout rates over the years in a selected state (e.g., Uttar
Pradesh, Tamil Nadu).

📁 Data Sources (assumed for demonstration)

 State Education Board records (1990–2024)


 DISE (District Information System for Education)
 Ministry of Education reports
 Census data
 MDMS Annual Reports

📊 1. Enrollment Trend Before and After MDMS

Hypothesis: MDMS increased school enrollment by reducing hunger barriers.

Year Enrollment (millions)

1990 3.1

1995 3.4 (MDMS Launched)

2000 4.2

2010 5.7

2020 6.1

2024 6.3
📈 Visualization: Line chart comparing enrollment before and after MDMS

Insight: A notable 80% increase in enrollment between 1995–2010 coincides with MDMS
implementation and scaling.

🧍 2. Dropout Rates Over Time

Year Dropout Rate (%)

1990 43

1995 41 (MDMS starts)

2000 36

2010 23

2020 14

2024 11

📉 Visualization: Area chart showing decline in dropout rates

Insight: Dropout rates halved within two decades of MDMS initiation. The sharpest decline
occurred during the program's expansion in early 2000s.

👥 3. Attendance Rates Before and After MDMS

Year Average Attendance (%)

1990 64

1995 67

2005 78

2015 85

2024 89

📊 Visualization: Bar graph comparing average attendance across decades

Insight: Regular attendance improved steadily, especially among rural and economically weaker
sections.
🔍 4. Gender-Specific Trends

 Girls’ dropout rate dropped from 49% (1995) to 16% (2024).


 MDMS provided nutritional support, reducing household burdens and increasing female
school participation.

📈 Visualization: Side-by-side bar charts showing male vs female dropout rates

Insight: Girls benefitted significantly—correlation with MDMS, girl-friendly school policies,


and awareness campaigns.

🌐 5. External Factors Affecting Dropout Rates

Event Impact

2001 SC ruling mandating cooked meals Boosted MDMS impact, improved food quality

RTE Act 2009 Increased school accessibility

COVID-19 (2020–21) Temporary rise in dropouts, mitigated by take-home rations

Digital learning gap Widened disparities, but MDMS ensured nutrition continuity

📌 Conclusion

The Mid-Day Meal Scheme has been a transformative social intervention, closely tied to:

 Rising enrollment
 Improved attendance
 Sharply reduced dropout rates, especially among girls and rural students

Correlation analysis shows:

 Negative correlation between meal implementation and dropout rates


 Positive correlation between attendance and nutritional support

📈 Recommended Visuals to Include

 Line chart: Enrollment over years


 Area chart: Dropout rate over years
 Bar chart: Attendance comparison (before/after MDMS)
 Gender comparison: Dropout rates
 Timeline: Key policy interventions
📒 How to Present in a Practical File

1. Create visuals in Excel, Python (matplotlib/seaborn), or Orange.


2. Insert snapshots of graphs with captions.
3. Summarize findings below each chart.
4. End with key takeaways and policy suggestions.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy