π Machine Learning Cheat Sheet π
1. Key Concepts:
- Supervised Learning: Learn from labeled data (e.g., classification, regression).
- Unsupervised Learning: Discover patterns in unlabeled data (e.g., clustering, dimensionality reduction).
- Reinforcement Learning: Learn by interacting with an environment to maximize reward.
2. Common Algorithms:
- Linear Regression: Predict continuous values.
- Logistic Regression: Binary classification.
- Decision Trees: Simple, interpretable model for classification and regression.
- Random Forests: Ensemble method for improved accuracy.
- Support Vector Machines: Effective for high-dimensional spaces.
- K-Nearest Neighbors: Instance-based learning for classification/regression.
- K-Means: Clustering algorithm.
- Principal Component Analysis(PCA)
3. Performance Metrics:
- Classification: Accuracy, Precision, Recall, F1-Score, ROC-AUC.
- Regression: Mean Absolute Error (MAE), Mean Squared Error (MSE), R^2 Score.
4. Data Preprocessing:
- Normalization: Scale features to a standard range.
- Standardization: Transform features to have zero mean and unit variance.
- Imputation: Handle missing data.
- Encoding: Convert categorical data into numerical format.
5. Model Evaluation:
- Cross-Validation: Ensure model generalization.
- Train-Test Split: Divide data to evaluate model performance.
6. Libraries:
- Python: Scikit-Learn, TensorFlow, Keras, PyTorch, Pandas, Numpy, Matplotlib.
- R: caret, randomForest, e1071, ggplot2.
7. Tips for Success:
- Feature Engineering: Enhance data quality and relevance.
- Hyperparameter Tuning: Optimize model parameters (Grid Search, Random Search).
- Model Interpretability: Use tools like SHAP and LIME.
- Continuous Learning: Stay updated with the latest research and trends.
π Dive into Machine Learning and transform data into insights! π
Best Data Science & Machine Learning Resources: https://topmate.io/coding/914624
All the best ππ
1. Key Concepts:
- Supervised Learning: Learn from labeled data (e.g., classification, regression).
- Unsupervised Learning: Discover patterns in unlabeled data (e.g., clustering, dimensionality reduction).
- Reinforcement Learning: Learn by interacting with an environment to maximize reward.
2. Common Algorithms:
- Linear Regression: Predict continuous values.
- Logistic Regression: Binary classification.
- Decision Trees: Simple, interpretable model for classification and regression.
- Random Forests: Ensemble method for improved accuracy.
- Support Vector Machines: Effective for high-dimensional spaces.
- K-Nearest Neighbors: Instance-based learning for classification/regression.
- K-Means: Clustering algorithm.
- Principal Component Analysis(PCA)
3. Performance Metrics:
- Classification: Accuracy, Precision, Recall, F1-Score, ROC-AUC.
- Regression: Mean Absolute Error (MAE), Mean Squared Error (MSE), R^2 Score.
4. Data Preprocessing:
- Normalization: Scale features to a standard range.
- Standardization: Transform features to have zero mean and unit variance.
- Imputation: Handle missing data.
- Encoding: Convert categorical data into numerical format.
5. Model Evaluation:
- Cross-Validation: Ensure model generalization.
- Train-Test Split: Divide data to evaluate model performance.
6. Libraries:
- Python: Scikit-Learn, TensorFlow, Keras, PyTorch, Pandas, Numpy, Matplotlib.
- R: caret, randomForest, e1071, ggplot2.
7. Tips for Success:
- Feature Engineering: Enhance data quality and relevance.
- Hyperparameter Tuning: Optimize model parameters (Grid Search, Random Search).
- Model Interpretability: Use tools like SHAP and LIME.
- Continuous Learning: Stay updated with the latest research and trends.
π Dive into Machine Learning and transform data into insights! π
Best Data Science & Machine Learning Resources: https://topmate.io/coding/914624
All the best ππ
β€8
β
Conditional Statements (ifβelse) πβ‘
Conditional statements allow programs to make decisions based on conditions.
π Used heavily in:
β Data filtering
β Business rules
β Machine learning logic
πΉ 1. if Statement
Used to execute code when a condition is True.
β Syntax
Example
# Output: You can vote
πΉ 2. ifβelse Statement
Used when there are two possible outcomes.
Syntax
Example
πΉ 3. ifβelifβelse Statement
Used when there are multiple conditions.
Syntax
Example
πΉ 4. Nested if Statement
An if statement inside another if.
πΉ 5. Short if (Ternary Operator)
π― Todayβs Goal
β Understand if
β Use ifβelse
β Use elif for multiple conditions
β Learn nested conditions
π Conditional logic is used in data filtering and decision models.
Double Tap β₯οΈ For More
Conditional statements allow programs to make decisions based on conditions.
π Used heavily in:
β Data filtering
β Business rules
β Machine learning logic
πΉ 1. if Statement
Used to execute code when a condition is True.
β Syntax
if condition:
# code
Example
age = 20
if age >= 18:
print("You can vote")
# Output: You can vote
πΉ 2. ifβelse Statement
Used when there are two possible outcomes.
Syntax
if condition:
# code if true
else:
# code if false
Example
age = 16
if age >= 18:
print("Eligible to vote")
else:
print("Not eligible")
πΉ 3. ifβelifβelse Statement
Used when there are multiple conditions.
Syntax
if condition1:
# code
elif condition2:
# code
else:
# code
Example
marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 60:
print("Grade B")
else:
print("Grade C")
πΉ 4. Nested if Statement
An if statement inside another if.
age = 20
citizen = True
if age >= 18:
if citizen:
print("Eligible to vote")
πΉ 5. Short if (Ternary Operator)
age = 20
print("Adult") if age >= 18 else print("Minor")
π― Todayβs Goal
β Understand if
β Use ifβelse
β Use elif for multiple conditions
β Learn nested conditions
π Conditional logic is used in data filtering and decision models.
Double Tap β₯οΈ For More
β€16π1
Which keyword is used to check a condition in Python?
Anonymous Quiz
9%
A) check
82%
B) if
4%
C) when
4%
D) condition
β€3
What will be the output?
x = 10 if x > 5: print("Yes") else: print("No")
x = 10 if x > 5: print("Yes") else: print("No")
Anonymous Quiz
89%
Yes
11%
No
β€3
Which keyword is used to check multiple conditions?
Anonymous Quiz
13%
A) elseif
60%
B) elif
23%
C) else if
4%
D) multiple
β€3
πΉ Q4. What will be the output?
x = 7 if x > 10: print("A") elif x > 5: print("B") else: print("C")
x = 7 if x > 10: print("A") elif x > 5: print("B") else: print("C")
Anonymous Quiz
13%
A
75%
B
10%
C
2%
D
β€2
What will be the output?
age = 16 print("Adult") if age >= 18 else print("Minor")
age = 16 print("Adult") if age >= 18 else print("Minor")
Anonymous Quiz
24%
Adult
76%
Minor
β€5π1
Now, let's move to the next topic of Data Science Roadmap:
β Python Dictionaries π
Dictionaries are one of the most important data structures in Python, especially in data science and real-world datasets. They store data in keyβvalue pairs.
πΉ 1. What is a Dictionary?
A dictionary stores data in key:value format.
β Example:
Output:
β Uses curly brackets {}
πΉ 2. Access Dictionary Values
Use the key to access values.
Output:
πΉ 3. Add New Elements
Output:
πΉ 4. Modify Values
πΉ 5. Remove Elements
πΉ 6. Important Dictionary Methods
β
β Get Method:
Output:
β Keys Method:
Output:
β Values Method:
Output:
β Items Method:
Output:
πΉ 7. Loop Through Dictionary
Output:
name Rahul
age 22
π― Todayβs Goal
β Understand keyβvalue pairs
β Access dictionary values
β Add or update data
β Loop through dictionary
π Dictionaries are widely used in APIs, JSON data, and machine learning datasets.
Double Tap β₯οΈ For More
β Python Dictionaries π
Dictionaries are one of the most important data structures in Python, especially in data science and real-world datasets. They store data in keyβvalue pairs.
πΉ 1. What is a Dictionary?
A dictionary stores data in key:value format.
β Example:
student = { "name": "Rahul", "age": 22, "course": "Data Science" }
print(student)
Output:
{'name': 'Rahul', 'age': 22, 'course': 'Data Science'}β Uses curly brackets {}
πΉ 2. Access Dictionary Values
Use the key to access values.
student = { "name": "Rahul", "age": 22 }
print(student["name"])
Output:
RahulπΉ 3. Add New Elements
student = { "name": "Rahul", "age": 22 }
student["city"] = "Delhi"
print(student)
Output:
{'name': 'Rahul', 'age': 22, 'city': 'Delhi'}πΉ 4. Modify Values
student["age"] = 23
πΉ 5. Remove Elements
student.pop("age")
πΉ 6. Important Dictionary Methods
β
β Get Method:
print(student.get("name"))
Output:
Rahulβ Keys Method:
print(student.keys())
Output:
dict_keys(['name', 'age'])β Values Method:
print(student.values())
Output:
dict_values(['Rahul', 22])β Items Method:
print(student.items())
Output:
dict_items([('name', 'Rahul'), ('age', 22)])πΉ 7. Loop Through Dictionary
student = { "name": "Rahul", "age": 22 }
for key, value in student.items():
print(key, value)
Output:
name Rahul
age 22
π― Todayβs Goal
β Understand keyβvalue pairs
β Access dictionary values
β Add or update data
β Loop through dictionary
π Dictionaries are widely used in APIs, JSON data, and machine learning datasets.
Double Tap β₯οΈ For More
β€21π₯°1
Which symbol is used to create a dictionary in Python?
Anonymous Quiz
18%
A) []
9%
B) ()
71%
C) {}
3%
D) <>
β€2π’1
What will be the output?
student = { "name": "Rahul", "age": 22 } print(student["name"])
student = { "name": "Rahul", "age": 22 } print(student["name"])
Anonymous Quiz
82%
A) Rahul
9%
B) name
3%
C) 22
7%
D) Error
β€2
Which method returns all keys of a dictionary?
Anonymous Quiz
14%
A) values()
14%
B) items()
61%
C) keys()
11%
D) get()
β€1
What will be the output?
data = {"a":1, "b":2} data["c"] = 3 print(data)
data = {"a":1, "b":2} data["c"] = 3 print(data)
Anonymous Quiz
9%
A) {'a':1, 'b':2}
65%
B) {'a':1, 'b':2, 'c':3}
18%
C) Error
8%
D) {'c':3}
β€1π€1
Which method is used to remove an element from a dictionary?
Anonymous Quiz
44%
A) remove()
16%
B) delete()
35%
C) pop()
5%
D) clearitem()
β€8
Data Science Roadmap
β Python File Handling
ππ File handling allows Python programs to read and write data from files.
π Very important in data science because most datasets come as:
β CSV files
β Text files
β Logs
β JSON files
πΉ 1. Opening a File
Python uses the open() function.
Syntax:
Example:
π "r" β Read mode
πΉ 2. File Modes
- "r" β Read file
- "w" β Write file (overwrites existing content)
- "a" β Append file (adds to existing content)
- "r+" β Read and write
πΉ 3. Reading a File
- Read Entire File:
- Read One Line:
- Read All Lines:
πΉ 4. Writing to a File
β "w" will overwrite existing content.
πΉ 5. Append to File
β Adds content without deleting old data.
πΉ 6. Best Practice (Very Important β)
Use with statement.
β Automatically closes the file.
πΉ 7. Why File Handling is Important?
Used for:
β Reading datasets
β Saving results
β Logging machine learning models
β Data preprocessing
π― Todayβs Goal
β Understand file modes
β Read files
β Write files
β Use with open()
π File handling is used heavily when working with CSV datasets in data science.
Double Tap β₯οΈ For More
β Python File Handling
ππ File handling allows Python programs to read and write data from files.
π Very important in data science because most datasets come as:
β CSV files
β Text files
β Logs
β JSON files
πΉ 1. Opening a File
Python uses the open() function.
Syntax:
open("filename", "mode")Example:
file = open("data.txt", "r")π "r" β Read mode
πΉ 2. File Modes
- "r" β Read file
- "w" β Write file (overwrites existing content)
- "a" β Append file (adds to existing content)
- "r+" β Read and write
πΉ 3. Reading a File
- Read Entire File:
file.read()- Read One Line:
file.readline()- Read All Lines:
file.readlines()πΉ 4. Writing to a File
file = open("data.txt", "w")
file.write("Hello Data Science")
file.close()
β "w" will overwrite existing content.
πΉ 5. Append to File
file = open("data.txt", "a")
file.write("\nNew line added")
file.close()
β Adds content without deleting old data.
πΉ 6. Best Practice (Very Important β)
Use with statement.
with open("data.txt", "r") as file:
content = file.read()
print(content)
β Automatically closes the file.
πΉ 7. Why File Handling is Important?
Used for:
β Reading datasets
β Saving results
β Logging machine learning models
β Data preprocessing
π― Todayβs Goal
β Understand file modes
β Read files
β Write files
β Use with open()
π File handling is used heavily when working with CSV datasets in data science.
Double Tap β₯οΈ For More
β€13
Which function is used to open a file in Python?
Anonymous Quiz
7%
A) file()
63%
B) open()
19%
C) read()
10%
D) openfile()
β€2
β€2
What will the following code do?
file = open("data.txt", "w") file.write("Hello")
file = open("data.txt", "w") file.write("Hello")
Anonymous Quiz
5%
A) Reads file
2%
B) Deletes file
90%
C) Writes text to file
4%
D) Prints file content
β€1
Which method reads the entire file content?
Anonymous Quiz
12%
A) readline()
27%
B) readlines()
58%
C) read()
3%
D) get()
β€1
Why is the with open() statement preferred?
Anonymous Quiz
27%
A) It runs faster
55%
B) It automatically closes the file
4%
C) It deletes the file
14%
D) It prevents writing
β€2π1π₯°1