Weather Data: Complete and Ward Linkages
The last chart was good, but if you remember the K-Means and K-Medoids algorithms results, you may remember that there was at least one more line that unlike all the others goes downwards close to July. The average linkage in hierarchical clustering didn't catch that dynamic.
We saw that for complete and ward linkages there is sense to consider 4 clusters. Let's find out will they catch that?
Swipe to start coding
- Import
numpywithnpalias. - Iterate over the
linkageslist. At each step:
- Create a hierarchical clustering model with 4 clusters and method
jnamedmodel. - Fit the numerical data of
tempand predict the labels. Add predicted labels as the'prediction'column totemp. - Create a
temp_resDataFrame with monthly averages for each group. To do it group the values oftempby the'prediction'column, calculate themean, and then apply the.stack()method. - Add column
'method'totemp_resDataFrame with valuejbeing repeated the number of rows intemp_restimes. - Merge
resandtemp_resdataframes using.concatfunction ofpd.
- Reassign the column names of
resto['Group', 'Month', 'Temp', "Method"]. - Within the
FacetGridfunction set thecolparameter to'Method'. This will build a separate chart for each value of the'Method'column. - Within the
.mapfunction set theseabornline plot function as the first parameter.
Рішення
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Сумаризуйте цей розділ
Пояснити код у file
Пояснити, чому file не вирішує завдання
Чудово!
Completion показник покращився до 3.57
Weather Data: Complete and Ward Linkages
Свайпніть щоб показати меню
The last chart was good, but if you remember the K-Means and K-Medoids algorithms results, you may remember that there was at least one more line that unlike all the others goes downwards close to July. The average linkage in hierarchical clustering didn't catch that dynamic.
We saw that for complete and ward linkages there is sense to consider 4 clusters. Let's find out will they catch that?
Swipe to start coding
- Import
numpywithnpalias. - Iterate over the
linkageslist. At each step:
- Create a hierarchical clustering model with 4 clusters and method
jnamedmodel. - Fit the numerical data of
tempand predict the labels. Add predicted labels as the'prediction'column totemp. - Create a
temp_resDataFrame with monthly averages for each group. To do it group the values oftempby the'prediction'column, calculate themean, and then apply the.stack()method. - Add column
'method'totemp_resDataFrame with valuejbeing repeated the number of rows intemp_restimes. - Merge
resandtemp_resdataframes using.concatfunction ofpd.
- Reassign the column names of
resto['Group', 'Month', 'Temp', "Method"]. - Within the
FacetGridfunction set thecolparameter to'Method'. This will build a separate chart for each value of the'Method'column. - Within the
.mapfunction set theseabornline plot function as the first parameter.
Рішення
Дякуємо за ваш відгук!
single