Data Science With A.I
Data Science With A.I
Ltd
NM 14, Ground floor, Opp. HDCF Bank, old dlf colony, Sec 14,
Example:
python
CopyEdit
def greet(name):
return f"Hello, {name}!"
print(greet("Alice"))
Example:
python
CopyEdit
# Binary Search Algorithm
def binary_search(arr, target):
low, high = 0, len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
Example:
python
CopyEdit
class Car:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def display(self):
print(f"Car: {self.brand} {self.model}")
Example:
python
CopyEdit
with open("sample.txt", "w") as file:
file.write("Hello, Python!")
Module 5: Python for Data Science
✅ NumPy (Arrays, Mathematical Operations)
✅ Pandas (DataFrames, Data Cleaning, Filtering)
✅ Matplotlib & Seaborn (Data Visualization)
Example:
python
CopyEdit
import pandas as pd
data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = pd.DataFrame(data)
print(df)
Example:
python
CopyEdit
from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array([1, 2, 3, 4, 5]).reshape(-1, 1)
y = np.array([2, 4, 6, 8, 10])
model = LinearRegression()
model.fit(X, y)
print(model.predict([[6]]))
Example:
python
CopyEdit
import tensorflow as tf
from tensorflow import keras
model = keras.Sequential([
keras.layers.Dense(64, activation='relu'),
keras.layers.Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam', loss='binary_crossentropy',
metrics=['accuracy'])
Example:
python
CopyEdit
import requests
from bs4 import BeautifulSoup
response = requests.get("https://example.com")
soup = BeautifulSoup(response.text, "html.parser")
print(soup.title.text)
Example:
python
CopyEdit
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return "Hello, Flask!"
if __name__ == "__main__":
app.run(debug=True)
# Creating a DataFrame
data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = pd.DataFrame(data)
# Sample Data
data = {'Category': ['A', 'B', 'C'], 'Values': [10, 15, 7]}
df = pd.DataFrame(data)
# Plot
sns.barplot(x='Category', y='Values', data=df)
plt.show()
X = np.array([1, 2, 3, 4, 5]).reshape(-1, 1)
y = np.array([2, 4, 6, 8, 10])
model = LinearRegression()
model.fit(X, y)
model = RandomForestClassifier(n_estimators=100)
model.fit(X_train, y_train)
Module 8: Deep Learning & Neural Networks
✅ Neural Networks (ANN, CNN, RNN)
✅ TensorFlow & Keras for Deep Learning
✅ Computer Vision (Image Recognition, Object Detection)
✅ Natural Language Processing (NLP) (Text Classification,
Sentiment Analysis)
model = keras.Sequential([
keras.layers.Dense(64, activation='relu'),
keras.layers.Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam', loss='binary_crossentropy',
metrics=['accuracy'])
# Sample Data
data = {'User': ['Alice', 'Bob'], 'Movie': ['Inception',
'Interstellar'], 'Rating': [5, 4]}
df = pd.DataFrame(data)
# Compute Similarity
similarity = cosine_similarity([[5], [4]])
print(similarity)
app = Flask(__name__)
model = pickle.load(open("model.pkl", "rb"))
@app.route('/predict', methods=['POST'])
def predict():
data = request.get_json()
prediction = model.predict([data['features']])
return jsonify({'prediction': prediction.tolist()})
if __name__ == '__main__':
app.run(debug=True)
# Load dataset
df = pd.read_csv("data.csv")
# Load dataset
df = pd.read_csv("data.csv")
# Plot heatmap
sns.heatmap(df.corr(), annot=True, cmap="coolwarm")
plt.show()
🔹 Module 5: Machine Learning Fundamentals
✅ Supervised Learning (Linear Regression, Logistic Regression,
Decision Trees, Random Forest)
✅ Unsupervised Learning (K-Means Clustering, PCA)
✅ Model Evaluation (Train-Test Split, Accuracy, Precision, Recall, F1-
Score)
X = np.array([1, 2, 3, 4, 5]).reshape(-1, 1)
y = np.array([2, 4, 6, 8, 10])
model = LinearRegression()
model.fit(X, y)
model = keras.Sequential([
keras.layers.Dense(64, activation='relu'),
keras.layers.Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam', loss='binary_crossentropy',
metrics=['accuracy'])
model = Sequential([
Conv2D(32, (3,3), activation='relu', input_shape=(64, 64, 3)),
MaxPooling2D(2,2),
Flatten(),
Dense(128, activation='relu'),
Dense(1, activation='sigmoid')
])
app = Flask(__name__)
model = pickle.load(open("model.pkl", "rb"))
@app.route('/predict', methods=['POST'])
def predict():
data = request.get_json()
prediction = model.predict([data['features']])
return jsonify({'prediction': prediction.tolist()})
if __name__ == '__main__':
app.run(debug=True)