<jupyter_start><jupyter_text>Day 49 Lecture 2 AssignmentIn this assignment, we will apply mean shift clustering to a dataset containing the results of a survey on financial wellbeing.<jupyter_code>%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn.cluster import MeanShift
from sklearn.preprocessing import StandardScaler<jupyter_output><empty_output><jupyter_text>This dataset contains the results of a survey on a financial wellbeing conducted by the US Consumer Finance Protection Bureau that were published in October 2017. This dataset has a large number of columns, most of which correspond to specific questions on the survey. These codebook for translating the column names to questions can be found here:https://s3.amazonaws.com/files.consumerfinance.gov/f/documents/cfpb_nfwbs-puf-codebook.pdfLoad the dataset.<jupyter_code># answer goes here

df = pd.read_csv('https://tf-assets-prod.s3.amazonaws.com/tf-curric/data-science/Data%20Sets%20Clustering/financial_wellbeing.csv')
df.head()<jupyter_output><empty_output><jupyter_text>While the survey questions have the potential for interesting cluster analysis, we will stick to the "score" columns to avoid clustering in an unreasonably high-dimensional space. The columns we are interested in all have "score" in their names; identify and isolate these columns. (There should be 4 in total.)<jupyter_code>df.columns
# answer goes here
df.columns<jupyter_output><empty_output><jupyter_text>Standardize the features in your dataset using scikit-learn's StandardScaler, which will set the mean of each feature to 0 and the variance to 1.<jupyter_code># answer goes here<jupyter_output><empty_output><jupyter_text>Run mean shift clustering on the scores in the survey dataset using the default bandwidth. Then answer the following by printing or typing as appropriate:- How many clusters are produced? - What are the cluster centers?- How many responses are assigned to each cluster?- Are these results reasonable? If not, what changes should we make?<jupyter_code># answer goes here<jupyter_output><empty_output><jupyter_text>Try changing the appropriate parameters of the mean shift algorithm to achieve a better clustering result. Answer all of the same questions from the previous clustering step.<jupyter_code># answer goes here<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.05820328975115985, 'fraction_numerical': 0.006748207507380852, 'mean_word_length': 6.2097264437689965, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '295371', 'license': 'MIT', 'n_tokens_mistral': 653, 'n_tokens_neox': 619, 'n_words': 273, 'path': 'week11/Day 49 Lecture 2 Assignment.ipynb', 'repo_name': 'mgalaviz1/my_work', 'size': '2371'}