handson-ml
handson-ml copied to clipboard
Ch.2 Error using corr()
I am getting the following error while using corr_matrix = housing.corr(), I know the method should exclude non-numerical columns, can't understand this error. " ValueError: could not convert string to float: 'INLAND' "
Try this:- housing_encoded = pd.get_dummies(housing, columns=['INLAND'], drop_first=True) corr_matrix = housing_encoded.corr()
TRY THIS WAY
housing_encoded = pd.get_dummies(housing, columns=['ocean_proximity'], drop_first=True) corr_matrix = housing_encoded.corr() corr_matrix["median_house_value"].sort_values(ascending=False)