Spaces:
Runtime error
Runtime error
Upload recommender_system.py
Browse files- recommender_system.py +5 -1
recommender_system.py
CHANGED
|
@@ -63,7 +63,7 @@ def recommend_books(df: pd.DataFrame, book_to_be_recommended: str) -> pd.DataFra
|
|
| 63 |
# Create DataFrame with correlations
|
| 64 |
correlations_df = pd.DataFrame({
|
| 65 |
'Book-Title': correlations.index,
|
| 66 |
-
'Correlation': correlations.values,
|
| 67 |
})
|
| 68 |
|
| 69 |
# Merge correlations_df with average_ratings
|
|
@@ -73,6 +73,10 @@ def recommend_books(df: pd.DataFrame, book_to_be_recommended: str) -> pd.DataFra
|
|
| 73 |
# Sort by correlation value
|
| 74 |
correlations_df = correlations_df.sort_values('Correlation', ascending=False)
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
# Remove the book being recommended from the list
|
| 77 |
correlations_df = correlations_df[correlations_df['Book-Title'] != book_to_be_recommended]
|
| 78 |
correlations_df = correlations_df.head(10)
|
|
|
|
| 63 |
# Create DataFrame with correlations
|
| 64 |
correlations_df = pd.DataFrame({
|
| 65 |
'Book-Title': correlations.index,
|
| 66 |
+
'Correlation [%]': correlations.values,
|
| 67 |
})
|
| 68 |
|
| 69 |
# Merge correlations_df with average_ratings
|
|
|
|
| 73 |
# Sort by correlation value
|
| 74 |
correlations_df = correlations_df.sort_values('Correlation', ascending=False)
|
| 75 |
|
| 76 |
+
# convert correlation column to percentage and limit to two decimals
|
| 77 |
+
correlations_df['Correlation'] = correlations_df['Correlation'] * 100
|
| 78 |
+
correlations_df['Correlation'] = correlations_df['Correlation'].round(2)
|
| 79 |
+
|
| 80 |
# Remove the book being recommended from the list
|
| 81 |
correlations_df = correlations_df[correlations_df['Book-Title'] != book_to_be_recommended]
|
| 82 |
correlations_df = correlations_df.head(10)
|