Solution: Customer Churn
Walk through the solution to the challenge.
We'll cover the following...
Here is the solution to the challenge of predicting ad clicks with logistic regression.
Press + to interact
# Task 1: Read the dataset 'ad_clicks.csv'df_adclicks = pd.read_csv('ad_clicks.csv')# Task 2: Select the following features for your model# Age, Gender, Income, Internet Usage, Time SpentX = df_adclicks[['Age', 'Gender', 'Income', 'Internet Usage', 'Time Spent']]# Task 3: Select 'Is Clicked' as the target labely = df_adclicks['Is Clicked']# Task 4: Split training and testing datasets (features and labels)# Use 30% of the dataset for testing# Use random_state=123 to have the same result as the solutionX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=123)# Task 5: Instantiate the model with max_iter=1000# And train your model with the training datasetlogreg = LogisticRegression(max_iter=1000)logreg.fit(X_train, y_train)# Task 6: Predict model performance with testing datasety_pred = logreg.predict(X_test)# Task 7: Calculate the accuracy, precision, and recall of your modelaccuracy = accuracy_score(y_test, y_pred)precision = precision_score(y_test, y_pred)recall = recall_score(y_test, y_pred)print('Accuracy:', round(accuracy, 1))print('Precision:', round(precision, 1))print('Recall:', round(recall, 1))
Explanation
Line 2 loads the dataset ...