pub struct TrainedModel {
pub classifier: Option<RandomForestClassifier>,
pub tfidf_extractor: Option<TfidfFeatureExtractor>,
pub category_to_label: HashMap<String, usize>,
pub label_to_category: HashMap<usize, String>,
pub metadata: TrainingMetadata,
pub tfidf_vocabulary: Vec<String>,
pub max_features: usize,
}Expand description
Trained ML classifier model with metadata
Fields§
§classifier: Option<RandomForestClassifier>Random Forest classifier
tfidf_extractor: Option<TfidfFeatureExtractor>TF-IDF feature extractor
category_to_label: HashMap<String, usize>Mapping from category to label index
label_to_category: HashMap<usize, String>Mapping from label index to category
metadata: TrainingMetadataTraining metadata
tfidf_vocabulary: Vec<String>TF-IDF vocabulary (for reconstruction)
max_features: usizeMax features for TF-IDF
Implementations§
Source§impl TrainedModel
impl TrainedModel
Sourcepub fn predict(&self, message: &str) -> Result<Option<(DefectCategory, f32)>>
pub fn predict(&self, message: &str) -> Result<Option<(DefectCategory, f32)>>
Predict defect category for a single commit message
§Arguments
message- Commit message to classify
§Returns
Ok(Some((DefectCategory, f32)))- Predicted category and confidenceOk(None)- Model components not available (deserialized model)Err- Prediction error
§Examples
if let Some((category, confidence)) = model.predict("fix: null pointer in parser")? {
println!("Predicted: {:?} ({:.2})", category, confidence);
}Sourcepub fn predict_top_n(
&self,
message: &str,
_top_n: usize,
) -> Result<Vec<(DefectCategory, f32)>>
pub fn predict_top_n( &self, message: &str, _top_n: usize, ) -> Result<Vec<(DefectCategory, f32)>>
Predict top-N defect categories for a commit message
§Arguments
message- Commit message to classifytop_n- Number of top categories to return
§Returns
Ok(Vec<(DefectCategory, f32)>)- Top-N categories with confidences
§Examples
let predictions = model.predict_top_n("fix: null pointer in parser", 3)?;
for (category, confidence) in predictions {
println!("{:?}: {:.2}", category, confidence);
}Trait Implementations§
Source§impl<'de> Deserialize<'de> for TrainedModel
impl<'de> Deserialize<'de> for TrainedModel
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for TrainedModel
impl !RefUnwindSafe for TrainedModel
impl !Send for TrainedModel
impl !Sync for TrainedModel
impl Unpin for TrainedModel
impl !UnwindSafe for TrainedModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> FromResponse for Twhere
T: DeserializeOwned,
impl<T> FromResponse for Twhere
T: DeserializeOwned,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.