Home > Back-end >  'DataFrame' object has no attribute 'raw_ratings'?
'DataFrame' object has no attribute 'raw_ratings'?

Time:12-08

param_grid = {'k': [10, 20, 30], 'min_k': [3, 6, 9],
              'sim_options': {'name': ["cosine", 'pearson', "pearson_baseline"],
                              'user_based': [False], "min_support": [2, 4]}
              }

# Performing 3-fold cross-validation to tune the hyperparameters
gs = GridSearchCV(KNNBasic, param_grid, measures=['rmse', 'mae'], cv=3, n_jobs=-1)


# Fitting the data
gs.fit(data)

# Find the best RMSE score
print(gs.best_score['rmse'])
# Extract the combination of parameters that gave the best RMSE score
print(gs.best_params['rmse'])

The above is the code that i entered

The error i recived is :

'DataFrame' object has no attribute 'raw_ratings'

the problem seems to be with gs.fit(data)

This line of code within the library is the reason for the error:

if self.n_splits > len(data.raw_ratings) or self.n_splits < 2:
     93         raise ValueError(
     94             "Incorrect value for n_splits={}. "
     95             "Must be >=2 and less than the number "
     96             "of ratings".format(len(data.raw_ratings))
     97         )

CodePudding user response:

I think we need to see what your data looks like !

Does it have the column associated to the attribute you want to access ?

To check try out :

# Print columns of the dataframe
print(data.columns)

# Or -> check all attributes/methodss
print(dir(data))

  • Related