Investments Example
Packages to load
[1]:
from ratingslib.datasets.filenames import FILENAME_INVESTMENTS, dataset_path
from ratingslib.ratings.aggregation import RankingAggregation, RatingAggregation
from ratingslib.utils.enums import ratings
from ratingslib.utils.methods import print_info
import pandas as pd
Set precision to 4 digits
[2]:
pd.set_option('float_format', "{:.4f}".format)
Get filename path and set columns dict (item, ratings)
[3]:
filename = dataset_path(FILENAME_INVESTMENTS)
columns_dict = {'item': 'investment',
'ratings': ['ROI', 'PP']}
RANKING AGGREGATION: 1. Average Rank 2. Borda count
[4]:
versions = [ratings.RANKINGAVG, ratings.RANKINGBORDA]
for version in versions:
print_info(version)
ra = RankingAggregation(version)
ratings_df = ra.rate_from_file(
filename, pairwise=False,
reverse_attributes_cols=['PP'],
columns_dict=columns_dict)
print(ratings_df)
=====AvgRank=====
Item rating ranking
0 investment1 2.0000 1
1 investment2 2.0000 1
2 investment3 2.0000 1
=====Borda=====
Item rating ranking
0 investment1 2.0000 1
1 investment2 2.0000 1
2 investment3 2.0000 1
RATING AGGREGATION: 1. Markov 2. OffenseDefense 3. Perron
[5]:
versions = [ratings.AGGREGATIONMARKOV,
ratings.AGGREGATIONOD,
ratings.AGGREGATIONPERRON]
for version in versions:
print_info(version)
ra = RatingAggregation(version)
ratings_df = ra.rate_from_file(
filename, pairwise=False,
reverse_attributes_cols=['PP'],
columns_dict=columns_dict)
print(ratings_df)
=====AggrMarkov=====
Item rating ranking
0 investment1 0.4186 1
1 investment2 0.2847 3
2 investment3 0.2967 2
=====AggrOD=====
Item rating ranking
0 investment1 0.8571 2
1 investment2 1.7097 1
2 investment3 0.8167 3
=====AggrPerron=====
Item rating ranking
0 investment1 0.3660 1
1 investment2 0.3237 2
2 investment3 0.3103 3