Class Xii PDF for Practical
Class Xii PDF for Practical
AND DATAFRAME
1. Creating a 2D Array:
import numpy as np
2. Accessing Elements:
import numpy as np
3. Array Arithmetic:
import numpy as np
# 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
# Random values
Print(a.T ) # Transpose
print(a – b) # Subtraction
print(a / b) # Division
📊 Aggregation Functions
Print(np.mean(a))
Print(np.std(a))
Print(np.max(a))
Print(np.min(a))
Print(np.argmax(a))
Print(np.argmin(a))
import pandas as pd
# From a dictionary
df = pd.DataFrame(data)
print(df)
2. Accessing Data:
import pandas as pd
df = pd.DataFrame(data)
print(df['Name'])
print(df[['Name', 'Age']])
print(df.iloc[0])
print(df.loc[0, 'Name'])
3. Data Filtering:
import pandas as pd
df = pd.DataFrame(data)
# Filter by age
# Filter by city
print(df[df['City'] == 'London'])
# Multiple conditions
✅ 1. Importing Libraries
import pandas as pd
import numpy as np
print(df.head())
df.to_csv('output.csv', index=False)
print(df.isnull().sum())
df_cleaned = df.dropna()
Assume your dataset has a feature column ['X'] and a target column ['Y'].
# Load dataset
df = pd.read_csv('data.csv')
df = df.dropna()
# Define X and y
# Train-test split
random_state=42)
# Model training
model = LinearRegression()
model.fit(X_train, y_train)
# Predict
y_pred = model.predict(X_test)
# Evaluate
print("Coefficient:", model.coef_)
print("Intercept:", model.intercept_)
# linear_regression
import pandas as pd
# Sample data
data = {
# Create DataFrame
df = pd.DataFrame(data)
# Split data
X = df[['X']] # Feature
y = df['Y'] # Target
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print("Predictions:", y_pred)
print("Actual:", y_test.values)
print("Coefficient:", model.coef_[0])
print("Intercept:", model.intercept_)
Chatbot Code
# gemini_chatbot.py
genai.configure(api_key="YOUR_GOOGLE_API_KEY")
model = genai.GenerativeModel("gemini-pro")
chat = model.start_chat()
while True:
print("Chatbot: Goodbye!")
break
response = chat.send_message(user_input)
print("Chatbot:", response.text)
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]
}
# 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.
🔹 Steps:
Canvas layout
Opened widgets (Box Plot, Scatter Plot, etc.)
✅ 2. Perform Classification in Orange
🔹 Steps:
🔹 Steps:
🔹 Steps:
📸 Snapshots:
🔹 Steps:
📸 Snapshots:
Data Visualization File → Box Plot, Scatter Plot, Distributions Graph displays
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.
🎯 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).
1990 3.1
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.
1990 43
2000 36
2010 23
2020 14
2024 11
Insight: Dropout rates halved within two decades of MDMS initiation. The sharpest decline
occurred during the program's expansion in early 2000s.
1990 64
1995 67
2005 78
2015 85
2024 89
Insight: Regular attendance improved steadily, especially among rural and economically weaker
sections.
🔍 4. Gender-Specific Trends
Event Impact
2001 SC ruling mandating cooked meals Boosted MDMS impact, improved food quality
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