Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create 3 equal-width bins for the data.
ML Python
import pandas as pd values = [1, 5, 8, 12, 15, 18] bins = pd.cut(values, [1]) print(bins)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list of bin edges instead of the number of bins.
Using pd.qcut instead of pd.cut for equal-width bins.
✗ Incorrect
Using pd.cut with the number 3 creates 3 equal-width bins.
2fill in blank
mediumComplete the code to create 4 bins with equal number of data points.
ML Python
import pandas as pd values = [2, 4, 6, 8, 10, 12, 14, 16] bins = pd.qcut(values, [1]) print(bins)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pd.cut instead of pd.qcut for equal-sized bins.
Passing the wrong number of bins.
✗ Incorrect
Using pd.qcut with 4 creates 4 bins each having roughly equal number of points.
3fill in blank
hardFix the error in the code to create bins with custom edges.
ML Python
import pandas as pd values = [3, 7, 11, 15, 19] bins = pd.cut(values, bins=[1]) print(bins)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for bin edges.
Passing a range object instead of a list.
✗ Incorrect
The bins argument must be a list or array of bin edges, so use square brackets.
4fill in blank
hardFill both blanks to create bins and label them as 'Low', 'Medium', 'High'.
ML Python
import pandas as pd values = [2, 5, 8, 11, 14] bins = pd.cut(values, [1], labels=[2]) print(bins)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using labels that don't match the number of bins.
Using bin edges that don't cover all data points.
✗ Incorrect
Use bin edges [0, 6, 12, 18] and labels ['Low', 'Medium', 'High'] to categorize values.
5fill in blank
hardFill all three blanks to create quantile bins, assign labels, and include the lowest value.
ML Python
import pandas as pd values = [1, 3, 5, 7, 9, 11] bins = pd.qcut(values, [1], labels=[2], [3]=True) print(bins)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter name instead of 'include_lowest'.
Mismatch between number of bins and labels.
✗ Incorrect
Use 3 quantile bins with labels and include_lowest=True to cover the smallest value.