def get_ratings_for_stable_init(
  ratingsForTraining: pd.DataFrame,
  userEnrollmentRaw: pd.DataFrame,
  modelingGroupToInitializeForStability: int,
  minPercentRatingsFromModelingGroup: float = 0.75,
  minNumRatingsToIncludeInStableInitialization: int = 5,
) -> pd.DataFrame:
  """Returns a subset of ratings to use for training an initial matrix factorization.
  Args:
      ratingsForTraining (pd.DataFrame)
      userEnrollmentRaw (pd.DataFrame)
      modelingGroupToInitializeForStability: modeling group for round 0 ratings
      minPercentRatingsFromModelingGroup: notes must have this fraction of ratings from the modeling group
      minNumRatingsToIncludeInStableInitialization: required from modeling group

  Returns:
      DF containing a subset of ratings
  """
  ratingsForTrainingWithModelingGroup = ratingsForTraining.merge(
    userEnrollmentRaw[[c.participantIdKey, c.modelingGroupKey]],
    left_on=c.raterParticipantIdKey,
    right_on=c.participantIdKey,
  )

  ratingsForTrainingWithModelingGroup[c.ratingFromInitialModelingGroupKey] = (
    ratingsForTrainingWithModelingGroup[c.modelingGroupKey] == modelingGroupToInitializeForStability
  )

  # Only include ratings from the modeling group
  ratingsForStableInitialization = ratingsForTrainingWithModelingGroup[
    ratingsForTrainingWithModelingGroup[c.ratingFromInitialModelingGroupKey]
  ]

  # Only include notes that have received at least 75% of their ratings from the modeling group (and 5 total)
  ratingsForTrainingWithModelingGroup[c.ratingCountKey] = 1
  noteStatsByRatedModelingGroup = (
    ratingsForTrainingWithModelingGroup[
      [c.noteIdKey, c.ratingFromInitialModelingGroupKey, c.ratingCountKey]
    ]
    .groupby(c.noteIdKey)
    .sum()
    .reset_index()
  )
  noteStatsByRatedModelingGroup[c.percentFromInitialModelingGroupKey] = (
    noteStatsByRatedModelingGroup[c.ratingFromInitialModelingGroupKey]
    / noteStatsByRatedModelingGroup[c.ratingCountKey]
  )
  noteStatsByRatedModelingGroup[
    c.percentFromInitialModelingGroupKey
  ] = noteStatsByRatedModelingGroup[c.percentFromInitialModelingGroupKey].fillna(0)
  notesRatedMostlyByInitialModelingGroup = noteStatsByRatedModelingGroup[
    (
      noteStatsByRatedModelingGroup[c.percentFromInitialModelingGroupKey]
      >= minPercentRatingsFromModelingGroup
    )
    & (
      noteStatsByRatedModelingGroup[c.ratingCountKey]
      >= minNumRatingsToIncludeInStableInitialization
    )
  ]
  ratingsForStableInitialization = ratingsForStableInitialization.merge(
    notesRatedMostlyByInitialModelingGroup[[c.noteIdKey]], on=c.noteIdKey
  )

  assert (
    len(ratingsForStableInitialization) > 0
  ), "No ratings from stable initialization modeling group."

  return ratingsForStableInitialization
Returns a subset of ratings to use for training an initial matrix factorization.
  Args:
      ratingsForTraining (pd.DataFrame)
      userEnrollmentRaw (pd.DataFrame)
      modelingGroupToInitializeForStability: modeling group for round 0 ratings
      minPercentRatingsFromModelingGroup: notes must have this fraction of ratings from the modeling group
      minNumRatingsToIncludeInStableInitialization: required from modeling group

  Returns:
      DF containing a subset of ratings
  
sourcecode/scoring/mf_base_scorer.py