| |
Methods defined here:
- __init__(self, rating_table=None, userid_column=None, itemid_column=None, rating_column=None, k=20, learning_rate=0.001, max_iternum=10, threshold=0.0002, item_similarity='Pearson', rating_table_sequence_column=None)
- DESCRIPTION:
The KNNRecommender function trains a interpolation weight model based on
weighted collaborative filtering approach. It uses the input user
ratings data to create three model tables: the weights model table,
the bias model table and the optional nearest items or neighbors table.
These tables are then used by KNNRecommenderPredict to predict the ratings or
preferences that users assign to entities like books, songs, movies
and other products.
PARAMETERS:
rating_table:
Required Argument.
Specifies the TeraDataMl DataFrame containing the user ratings.
userid_column:
Optional Argument.
Specifies the user id column in the rating table. The default is the first
column in the rating table.
Types: str
itemid_column:
Optional Argument.
Specifies the item id column in the rating table. The default is the second
column in the rating table.
Types: str
rating_column:
Optional Argument.
Specifies the rating column in the rating table. The default is the third
column in the rating table.
Types: str
k:
Optional Argument.
Specifies the number of nearest neighbors used in the calculation of the
interpolation weights.
Default Value: 20
Types: int
learning_rate:
Optional Argument.
Specifies initial learning rate. The learning rate adjusts automatically during
training based on changes in the rmse.
Default Value: 0.001
Types: float
max_iternum:
Optional Argument.
Specifies the maximum number of iterations.
Default Value: 10
Types: int
threshold:
Optional Argument.
The function stops when the rmse drops below this level.
Default Value: 2.0E-4
Types: float
item_similarity:
Optional Argument.
Specifies the method used to calculate item similarity. Options include: Pearson (Pearson
correlation coefficient), adjustedcosine (adjusted cosine similarity)
Default Value: "Pearson"
Permitted Values: AdjustedCosine, Pearson
Types: str
rating_table_sequence_column:
Optional Argument.
Specifies the list of column(s) that uniquely identifies each row of
the input argument "rating_table". The argument is used to ensure
deterministic results for functions which produce results that vary
from run to run.
Types: str OR list of Strings (str)
RETURNS:
Instance of KNNRecommender.
Output teradataml DataFrames can be accessed using attribute
references, such as KNNRecommenderObj.<attribute_name>.
Output teradataml DataFrame attribute names are:
1. weight_model_table
2. bias_model_table
3. nearest_items
4. output
RAISES:
TeradataMlException
EXAMPLES:
# Load the data to run the example
load_example_data("knnrecommender", "ml_ratings")
# Create teradataml DataFrame objects.
# The ml_ratings table has movie ratings from 50 users on
# approximately 2900 movies, with an average of about 150 ratings
# for each user. The 10 possible ratings range from 0.5 to 5
# in steps of 0.5. A higher number indicates a better rating.
ml_ratings = DataFrame.from_table("ml_ratings")
# Example 1 - Train the KNN Recommender system on the user ratings data
knn_recommender_out = KNNRecommender(rating_table = ml_ratings,
userid_column = "userid",
itemid_column = "itemid",
rating_column = "rating"
)
# Print the result DataFrame
print(knn_recommender_out)
- __repr__(self)
- Returns the string representation for a KNNRecommender class instance.
- get_build_time(self)
- Function to return the build time of the algorithm in seconds.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
- get_prediction_type(self)
- Function to return the Prediction type of the algorithm.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
- get_target_column(self)
- Function to return the Target Column of the algorithm.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
- show_query(self)
- Function to return the underlying SQL query.
When model object is created using retrieve_model(), then None is returned.
|