Complete the code to define a rule-based system that checks if a number is positive.
def is_positive(num): return num [1] 0
The rule-based system checks if the number is greater than zero to decide if it is positive.
Complete the code to train a simple machine learning model using scikit-learn.
from sklearn.linear_model import LinearRegression model = LinearRegression() model.[1](X_train, y_train)
predict instead of fit will cause an error because the model is not trained yet.The fit method trains the model on the training data.
Fix the error in the code that predicts labels using a trained model.
predictions = model.[1](X_test)fit here will retrain the model instead of predicting.The predict method is used to get predictions from the model on new data.
Fill both blanks to create a simple rule-based decision function.
def decide_action(temp): if temp [1] 30: return '[2]' else: return 'Stay inside'
The function returns 'Go outside' if the temperature is greater than 30, otherwise 'Stay inside'.
Fill all three blanks to create a dictionary comprehension that maps words to their lengths if length is greater than 3.
lengths = { [1]: [2] for [3] in words if len([3]) > 3 }This dictionary comprehension creates a dictionary where keys are words and values are their lengths, but only for words longer than 3 characters.