Initial commit
Browse files- README.md +267 -0
- config.json +21 -0
- confusion_matrix.png +0 -0
- main.py +164 -0
- model.pkl +3 -0
- roc_curve.png +0 -0
README.md
CHANGED
|
@@ -1,3 +1,270 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
+
library_name: sklearn
|
| 4 |
+
tags:
|
| 5 |
+
- sklearn
|
| 6 |
+
- skops
|
| 7 |
+
- text-classification
|
| 8 |
+
model_format: pickle
|
| 9 |
+
model_file: model.pkl
|
| 10 |
---
|
| 11 |
+
|
| 12 |
+
# Model description
|
| 13 |
+
|
| 14 |
+
[More Information Needed]
|
| 15 |
+
|
| 16 |
+
## Intended uses & limitations
|
| 17 |
+
|
| 18 |
+
[More Information Needed]
|
| 19 |
+
|
| 20 |
+
## Training Procedure
|
| 21 |
+
|
| 22 |
+
[More Information Needed]
|
| 23 |
+
|
| 24 |
+
### Hyperparameters
|
| 25 |
+
|
| 26 |
+
<details>
|
| 27 |
+
<summary> Click to expand </summary>
|
| 28 |
+
|
| 29 |
+
| Hyperparameter | Value |
|
| 30 |
+
|-------------------------------------|-------------------------------------------|
|
| 31 |
+
| memory | |
|
| 32 |
+
| steps | [('tfidf', TfidfVectorizer(min_df=100, ngram_range=(1, 3),<br /> preprocessor=<function preprocessor at 0x7fa438e7a280>)), ('classifier', XGBClassifier(base_score=None, booster=None, callbacks=None,<br /> colsample_bylevel=None, colsample_bynode=None,<br /> colsample_bytree=None, device=None, early_stopping_rounds=None,<br /> enable_categorical=False, eval_metric=None, feature_types=None,<br /> gamma=None, grow_policy=None, importance_type=None,<br /> interaction_constraints=None, learning_rate=None, max_bin=None,<br /> max_cat_threshold=None, max_cat_to_onehot=None,<br /> max_delta_step=None, max_depth=None, max_leaves=None,<br /> min_child_weight=None, missing=nan, monotone_constraints=None,<br /> multi_strategy=None, n_estimators=None, n_jobs=None,<br /> num_parallel_tree=None, random_state=None, ...))] |
|
| 33 |
+
| verbose | True |
|
| 34 |
+
| tfidf | TfidfVectorizer(min_df=100, ngram_range=(1, 3),<br /> preprocessor=<function preprocessor at 0x7fa438e7a280>) |
|
| 35 |
+
| classifier | XGBClassifier(base_score=None, booster=None, callbacks=None,<br /> colsample_bylevel=None, colsample_bynode=None,<br /> colsample_bytree=None, device=None, early_stopping_rounds=None,<br /> enable_categorical=False, eval_metric=None, feature_types=None,<br /> gamma=None, grow_policy=None, importance_type=None,<br /> interaction_constraints=None, learning_rate=None, max_bin=None,<br /> max_cat_threshold=None, max_cat_to_onehot=None,<br /> max_delta_step=None, max_depth=None, max_leaves=None,<br /> min_child_weight=None, missing=nan, monotone_constraints=None,<br /> multi_strategy=None, n_estimators=None, n_jobs=None,<br /> num_parallel_tree=None, random_state=None, ...) |
|
| 36 |
+
| tfidf__analyzer | word |
|
| 37 |
+
| tfidf__binary | False |
|
| 38 |
+
| tfidf__decode_error | strict |
|
| 39 |
+
| tfidf__dtype | <class 'numpy.float64'> |
|
| 40 |
+
| tfidf__encoding | utf-8 |
|
| 41 |
+
| tfidf__input | content |
|
| 42 |
+
| tfidf__lowercase | True |
|
| 43 |
+
| tfidf__max_df | 1.0 |
|
| 44 |
+
| tfidf__max_features | |
|
| 45 |
+
| tfidf__min_df | 100 |
|
| 46 |
+
| tfidf__ngram_range | (1, 3) |
|
| 47 |
+
| tfidf__norm | l2 |
|
| 48 |
+
| tfidf__preprocessor | <function preprocessor at 0x7fa438e7a280> |
|
| 49 |
+
| tfidf__smooth_idf | True |
|
| 50 |
+
| tfidf__stop_words | |
|
| 51 |
+
| tfidf__strip_accents | |
|
| 52 |
+
| tfidf__sublinear_tf | False |
|
| 53 |
+
| tfidf__token_pattern | (?u)\b\w\w+\b |
|
| 54 |
+
| tfidf__tokenizer | |
|
| 55 |
+
| tfidf__use_idf | True |
|
| 56 |
+
| tfidf__vocabulary | |
|
| 57 |
+
| classifier__objective | binary:logistic |
|
| 58 |
+
| classifier__base_score | |
|
| 59 |
+
| classifier__booster | |
|
| 60 |
+
| classifier__callbacks | |
|
| 61 |
+
| classifier__colsample_bylevel | |
|
| 62 |
+
| classifier__colsample_bynode | |
|
| 63 |
+
| classifier__colsample_bytree | |
|
| 64 |
+
| classifier__device | |
|
| 65 |
+
| classifier__early_stopping_rounds | |
|
| 66 |
+
| classifier__enable_categorical | False |
|
| 67 |
+
| classifier__eval_metric | |
|
| 68 |
+
| classifier__feature_types | |
|
| 69 |
+
| classifier__gamma | |
|
| 70 |
+
| classifier__grow_policy | |
|
| 71 |
+
| classifier__importance_type | |
|
| 72 |
+
| classifier__interaction_constraints | |
|
| 73 |
+
| classifier__learning_rate | |
|
| 74 |
+
| classifier__max_bin | |
|
| 75 |
+
| classifier__max_cat_threshold | |
|
| 76 |
+
| classifier__max_cat_to_onehot | |
|
| 77 |
+
| classifier__max_delta_step | |
|
| 78 |
+
| classifier__max_depth | |
|
| 79 |
+
| classifier__max_leaves | |
|
| 80 |
+
| classifier__min_child_weight | |
|
| 81 |
+
| classifier__missing | nan |
|
| 82 |
+
| classifier__monotone_constraints | |
|
| 83 |
+
| classifier__multi_strategy | |
|
| 84 |
+
| classifier__n_estimators | |
|
| 85 |
+
| classifier__n_jobs | |
|
| 86 |
+
| classifier__num_parallel_tree | |
|
| 87 |
+
| classifier__random_state | |
|
| 88 |
+
| classifier__reg_alpha | |
|
| 89 |
+
| classifier__reg_lambda | |
|
| 90 |
+
| classifier__sampling_method | |
|
| 91 |
+
| classifier__scale_pos_weight | |
|
| 92 |
+
| classifier__subsample | |
|
| 93 |
+
| classifier__tree_method | |
|
| 94 |
+
| classifier__validate_parameters | |
|
| 95 |
+
| classifier__verbosity | |
|
| 96 |
+
|
| 97 |
+
</details>
|
| 98 |
+
|
| 99 |
+
### Model Plot
|
| 100 |
+
|
| 101 |
+
<style>#sk-container-id-1 {/* Definition of color scheme common for light and dark mode */--sklearn-color-text: black;--sklearn-color-line: gray;/* Definition of color scheme for unfitted estimators */--sklearn-color-unfitted-level-0: #fff5e6;--sklearn-color-unfitted-level-1: #f6e4d2;--sklearn-color-unfitted-level-2: #ffe0b3;--sklearn-color-unfitted-level-3: chocolate;/* Definition of color scheme for fitted estimators */--sklearn-color-fitted-level-0: #f0f8ff;--sklearn-color-fitted-level-1: #d4ebff;--sklearn-color-fitted-level-2: #b3dbfd;--sklearn-color-fitted-level-3: cornflowerblue;/* Specific color for light theme */--sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));--sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));--sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));--sklearn-color-icon: #696969;@media (prefers-color-scheme: dark) {/* Redefinition of color scheme for dark theme */--sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));--sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));--sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));--sklearn-color-icon: #878787;}
|
| 102 |
+
}#sk-container-id-1 {color: var(--sklearn-color-text);
|
| 103 |
+
}#sk-container-id-1 pre {padding: 0;
|
| 104 |
+
}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;
|
| 105 |
+
}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed var(--sklearn-color-line);margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: var(--sklearn-color-background);
|
| 106 |
+
}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }`but bootstrap.min.css set `[hidden] { display: none !important; }`so we also need the `!important` here to be able to override thedefault hidden behavior on the sphinx rendered scikit-learn.org.See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;
|
| 107 |
+
}#sk-container-id-1 div.sk-text-repr-fallback {display: none;
|
| 108 |
+
}div.sk-parallel-item,
|
| 109 |
+
div.sk-serial,
|
| 110 |
+
div.sk-item {/* draw centered vertical line to link estimators */background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));background-size: 2px 100%;background-repeat: no-repeat;background-position: center center;
|
| 111 |
+
}/* Parallel-specific style estimator block */#sk-container-id-1 div.sk-parallel-item::after {content: "";width: 100%;border-bottom: 2px solid var(--sklearn-color-text-on-default-background);flex-grow: 1;
|
| 112 |
+
}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: var(--sklearn-color-background);position: relative;
|
| 113 |
+
}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;
|
| 114 |
+
}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;
|
| 115 |
+
}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;
|
| 116 |
+
}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;
|
| 117 |
+
}/* Serial-specific style estimator block */#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: var(--sklearn-color-background);padding-right: 1em;padding-left: 1em;
|
| 118 |
+
}/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is
|
| 119 |
+
clickable and can be expanded/collapsed.
|
| 120 |
+
- Pipeline and ColumnTransformer use this feature and define the default style
|
| 121 |
+
- Estimators will overwrite some part of the style using the `sk-estimator` class
|
| 122 |
+
*//* Pipeline and ColumnTransformer style (default) */#sk-container-id-1 div.sk-toggleable {/* Default theme specific background. It is overwritten whether we have aspecific estimator or a Pipeline/ColumnTransformer */background-color: var(--sklearn-color-background);
|
| 123 |
+
}/* Toggleable label */
|
| 124 |
+
#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.5em;box-sizing: border-box;text-align: center;
|
| 125 |
+
}#sk-container-id-1 label.sk-toggleable__label-arrow:before {/* Arrow on the left of the label */content: "▸";float: left;margin-right: 0.25em;color: var(--sklearn-color-icon);
|
| 126 |
+
}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: var(--sklearn-color-text);
|
| 127 |
+
}/* Toggleable content - dropdown */#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;/* unfitted */background-color: var(--sklearn-color-unfitted-level-0);
|
| 128 |
+
}#sk-container-id-1 div.sk-toggleable__content.fitted {/* fitted */background-color: var(--sklearn-color-fitted-level-0);
|
| 129 |
+
}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;border-radius: 0.25em;color: var(--sklearn-color-text);/* unfitted */background-color: var(--sklearn-color-unfitted-level-0);
|
| 130 |
+
}#sk-container-id-1 div.sk-toggleable__content.fitted pre {/* unfitted */background-color: var(--sklearn-color-fitted-level-0);
|
| 131 |
+
}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {/* Expand drop-down */max-height: 200px;max-width: 100%;overflow: auto;
|
| 132 |
+
}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: "▾";
|
| 133 |
+
}/* Pipeline/ColumnTransformer-specific style */#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {color: var(--sklearn-color-text);background-color: var(--sklearn-color-unfitted-level-2);
|
| 134 |
+
}#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: var(--sklearn-color-fitted-level-2);
|
| 135 |
+
}/* Estimator-specific style *//* Colorize estimator box */
|
| 136 |
+
#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {/* unfitted */background-color: var(--sklearn-color-unfitted-level-2);
|
| 137 |
+
}#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {/* fitted */background-color: var(--sklearn-color-fitted-level-2);
|
| 138 |
+
}#sk-container-id-1 div.sk-label label.sk-toggleable__label,
|
| 139 |
+
#sk-container-id-1 div.sk-label label {/* The background is the default theme color */color: var(--sklearn-color-text-on-default-background);
|
| 140 |
+
}/* On hover, darken the color of the background */
|
| 141 |
+
#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {color: var(--sklearn-color-text);background-color: var(--sklearn-color-unfitted-level-2);
|
| 142 |
+
}/* Label box, darken color on hover, fitted */
|
| 143 |
+
#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {color: var(--sklearn-color-text);background-color: var(--sklearn-color-fitted-level-2);
|
| 144 |
+
}/* Estimator label */#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;
|
| 145 |
+
}#sk-container-id-1 div.sk-label-container {text-align: center;
|
| 146 |
+
}/* Estimator-specific */
|
| 147 |
+
#sk-container-id-1 div.sk-estimator {font-family: monospace;border: 1px dotted var(--sklearn-color-border-box);border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;/* unfitted */background-color: var(--sklearn-color-unfitted-level-0);
|
| 148 |
+
}#sk-container-id-1 div.sk-estimator.fitted {/* fitted */background-color: var(--sklearn-color-fitted-level-0);
|
| 149 |
+
}/* on hover */
|
| 150 |
+
#sk-container-id-1 div.sk-estimator:hover {/* unfitted */background-color: var(--sklearn-color-unfitted-level-2);
|
| 151 |
+
}#sk-container-id-1 div.sk-estimator.fitted:hover {/* fitted */background-color: var(--sklearn-color-fitted-level-2);
|
| 152 |
+
}/* Specification for estimator info (e.g. "i" and "?") *//* Common style for "i" and "?" */.sk-estimator-doc-link,
|
| 153 |
+
a:link.sk-estimator-doc-link,
|
| 154 |
+
a:visited.sk-estimator-doc-link {float: right;font-size: smaller;line-height: 1em;font-family: monospace;background-color: var(--sklearn-color-background);border-radius: 1em;height: 1em;width: 1em;text-decoration: none !important;margin-left: 1ex;/* unfitted */border: var(--sklearn-color-unfitted-level-1) 1pt solid;color: var(--sklearn-color-unfitted-level-1);
|
| 155 |
+
}.sk-estimator-doc-link.fitted,
|
| 156 |
+
a:link.sk-estimator-doc-link.fitted,
|
| 157 |
+
a:visited.sk-estimator-doc-link.fitted {/* fitted */border: var(--sklearn-color-fitted-level-1) 1pt solid;color: var(--sklearn-color-fitted-level-1);
|
| 158 |
+
}/* On hover */
|
| 159 |
+
div.sk-estimator:hover .sk-estimator-doc-link:hover,
|
| 160 |
+
.sk-estimator-doc-link:hover,
|
| 161 |
+
div.sk-label-container:hover .sk-estimator-doc-link:hover,
|
| 162 |
+
.sk-estimator-doc-link:hover {/* unfitted */background-color: var(--sklearn-color-unfitted-level-3);color: var(--sklearn-color-background);text-decoration: none;
|
| 163 |
+
}div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,
|
| 164 |
+
.sk-estimator-doc-link.fitted:hover,
|
| 165 |
+
div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,
|
| 166 |
+
.sk-estimator-doc-link.fitted:hover {/* fitted */background-color: var(--sklearn-color-fitted-level-3);color: var(--sklearn-color-background);text-decoration: none;
|
| 167 |
+
}/* Span, style for the box shown on hovering the info icon */
|
| 168 |
+
.sk-estimator-doc-link span {display: none;z-index: 9999;position: relative;font-weight: normal;right: .2ex;padding: .5ex;margin: .5ex;width: min-content;min-width: 20ex;max-width: 50ex;color: var(--sklearn-color-text);box-shadow: 2pt 2pt 4pt #999;/* unfitted */background: var(--sklearn-color-unfitted-level-0);border: .5pt solid var(--sklearn-color-unfitted-level-3);
|
| 169 |
+
}.sk-estimator-doc-link.fitted span {/* fitted */background: var(--sklearn-color-fitted-level-0);border: var(--sklearn-color-fitted-level-3);
|
| 170 |
+
}.sk-estimator-doc-link:hover span {display: block;
|
| 171 |
+
}/* "?"-specific style due to the `<a>` HTML tag */#sk-container-id-1 a.estimator_doc_link {float: right;font-size: 1rem;line-height: 1em;font-family: monospace;background-color: var(--sklearn-color-background);border-radius: 1rem;height: 1rem;width: 1rem;text-decoration: none;/* unfitted */color: var(--sklearn-color-unfitted-level-1);border: var(--sklearn-color-unfitted-level-1) 1pt solid;
|
| 172 |
+
}#sk-container-id-1 a.estimator_doc_link.fitted {/* fitted */border: var(--sklearn-color-fitted-level-1) 1pt solid;color: var(--sklearn-color-fitted-level-1);
|
| 173 |
+
}/* On hover */
|
| 174 |
+
#sk-container-id-1 a.estimator_doc_link:hover {/* unfitted */background-color: var(--sklearn-color-unfitted-level-3);color: var(--sklearn-color-background);text-decoration: none;
|
| 175 |
+
}#sk-container-id-1 a.estimator_doc_link.fitted:hover {/* fitted */background-color: var(--sklearn-color-fitted-level-3);
|
| 176 |
+
}
|
| 177 |
+
</style><div id="sk-container-id-1" class="sk-top-container" style="overflow: auto;"><div class="sk-text-repr-fallback"><pre>Pipeline(steps=[('tfidf',TfidfVectorizer(min_df=100, ngram_range=(1, 3),preprocessor=<function preprocessor at 0x7fa438e7a280>)),('classifier',XGBClassifier(base_score=None, booster=None, callbacks=None,colsample_bylevel=None, colsample_bynode=None,colsample_bytree=None, device=None,early_stopping_rounds=None,enable_categorical=False, eval_metric=None,featur...importance_type=None,interaction_constraints=None, learning_rate=None,max_bin=None, max_cat_threshold=None,max_cat_to_onehot=None, max_delta_step=None,max_depth=None, max_leaves=None,min_child_weight=None, missing=nan,monotone_constraints=None, multi_strategy=None,n_estimators=None, n_jobs=None,num_parallel_tree=None, random_state=None, ...))],verbose=True)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden><div class="sk-item sk-dashed-wrapped"><div class="sk-label-container"><div class="sk-label fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually" id="sk-estimator-id-1" type="checkbox" ><label for="sk-estimator-id-1" class="sk-toggleable__label fitted sk-toggleable__label-arrow fitted"> Pipeline<a class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.4/modules/generated/sklearn.pipeline.Pipeline.html">?<span>Documentation for Pipeline</span></a><span class="sk-estimator-doc-link fitted">i<span>Fitted</span></span></label><div class="sk-toggleable__content fitted"><pre>Pipeline(steps=[('tfidf',TfidfVectorizer(min_df=100, ngram_range=(1, 3),preprocessor=<function preprocessor at 0x7fa438e7a280>)),('classifier',XGBClassifier(base_score=None, booster=None, callbacks=None,colsample_bylevel=None, colsample_bynode=None,colsample_bytree=None, device=None,early_stopping_rounds=None,enable_categorical=False, eval_metric=None,featur...importance_type=None,interaction_constraints=None, learning_rate=None,max_bin=None, max_cat_threshold=None,max_cat_to_onehot=None, max_delta_step=None,max_depth=None, max_leaves=None,min_child_weight=None, missing=nan,monotone_constraints=None, multi_strategy=None,n_estimators=None, n_jobs=None,num_parallel_tree=None, random_state=None, ...))],verbose=True)</pre></div> </div></div><div class="sk-serial"><div class="sk-item"><div class="sk-estimator fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually" id="sk-estimator-id-2" type="checkbox" ><label for="sk-estimator-id-2" class="sk-toggleable__label fitted sk-toggleable__label-arrow fitted"> TfidfVectorizer<a class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.4/modules/generated/sklearn.feature_extraction.text.TfidfVectorizer.html">?<span>Documentation for TfidfVectorizer</span></a></label><div class="sk-toggleable__content fitted"><pre>TfidfVectorizer(min_df=100, ngram_range=(1, 3),preprocessor=<function preprocessor at 0x7fa438e7a280>)</pre></div> </div></div><div class="sk-item"><div class="sk-estimator fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually" id="sk-estimator-id-3" type="checkbox" ><label for="sk-estimator-id-3" class="sk-toggleable__label fitted sk-toggleable__label-arrow fitted">XGBClassifier</label><div class="sk-toggleable__content fitted"><pre>XGBClassifier(base_score=None, booster=None, callbacks=None,colsample_bylevel=None, colsample_bynode=None,colsample_bytree=None, device=None, early_stopping_rounds=None,enable_categorical=False, eval_metric=None, feature_types=None,gamma=None, grow_policy=None, importance_type=None,interaction_constraints=None, learning_rate=None, max_bin=None,max_cat_threshold=None, max_cat_to_onehot=None,max_delta_step=None, max_depth=None, max_leaves=None,min_child_weight=None, missing=nan, monotone_constraints=None,multi_strategy=None, n_estimators=None, n_jobs=None,num_parallel_tree=None, random_state=None, ...)</pre></div> </div></div></div></div></div></div>
|
| 178 |
+
|
| 179 |
+
## Evaluation Results
|
| 180 |
+
|
| 181 |
+
| Metric | Value |
|
| 182 |
+
|----------|----------|
|
| 183 |
+
| accuracy | 0.910317 |
|
| 184 |
+
| f1 score | 0.910317 |
|
| 185 |
+
|
| 186 |
+
# How to Get Started with the Model
|
| 187 |
+
|
| 188 |
+
[More Information Needed]
|
| 189 |
+
|
| 190 |
+
# Model Card Authors
|
| 191 |
+
|
| 192 |
+
This model card is written by following authors:
|
| 193 |
+
|
| 194 |
+
[More Information Needed]
|
| 195 |
+
|
| 196 |
+
# Model Card Contact
|
| 197 |
+
|
| 198 |
+
You can contact the model card authors through following channels:
|
| 199 |
+
[More Information Needed]
|
| 200 |
+
|
| 201 |
+
# Citation
|
| 202 |
+
|
| 203 |
+
Below you can find information related to citation.
|
| 204 |
+
|
| 205 |
+
**BibTeX:**
|
| 206 |
+
```
|
| 207 |
+
[More Information Needed]
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
# get_started_code
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
import sklearn
|
| 214 |
+
import dill as pickle
|
| 215 |
+
|
| 216 |
+
from skops import hub_utils
|
| 217 |
+
from pathlib import Path
|
| 218 |
+
|
| 219 |
+
suicide_detector_repo = Path("./suicide-detector")
|
| 220 |
+
|
| 221 |
+
hub_utils.download(
|
| 222 |
+
repo_id="AndyJamesTurner/suicideDetector",
|
| 223 |
+
dst=suicide_detector_repo
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
with open(suicide_detector_repo / "model.pkl", 'rb') as file:
|
| 227 |
+
clf = pickle.load(file)
|
| 228 |
+
|
| 229 |
+
classification = clf.predict(["I want to kill myself"])[0]
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
# model_card_authors
|
| 233 |
+
|
| 234 |
+
Andy Turner
|
| 235 |
+
|
| 236 |
+
# model_description
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
Suicide Detection text classification model.
|
| 240 |
+
|
| 241 |
+
Trained on the Suicide and Depression Detection dataset (https://www.kaggle.com/datasets/nikhileswarkomati/suicide-watch)
|
| 242 |
+
|
| 243 |
+
The model vectorises each text using a trained tfidf vectorizer and then classifies using xgboost.
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
# eval_method
|
| 247 |
+
|
| 248 |
+
The model was evaluated on a 0.3 holdout split using f1 score, accuracy, confusion matrix and ROC curves.
|
| 249 |
+
|
| 250 |
+
# Confusion matrix
|
| 251 |
+
|
| 252 |
+

|
| 253 |
+
|
| 254 |
+
# ROC Curve
|
| 255 |
+
|
| 256 |
+

|
| 257 |
+
|
| 258 |
+
# Classification Report
|
| 259 |
+
|
| 260 |
+
<details>
|
| 261 |
+
<summary> Click to expand </summary>
|
| 262 |
+
|
| 263 |
+
| index | precision | recall | f1-score | support |
|
| 264 |
+
|--------------|-------------|----------|------------|-----------|
|
| 265 |
+
| not suicide | 0.891721 | 0.934126 | 0.912431 | 34824 |
|
| 266 |
+
| suicide | 0.930785 | 0.886491 | 0.908098 | 34799 |
|
| 267 |
+
| macro avg | 0.911253 | 0.910308 | 0.910265 | 69623 |
|
| 268 |
+
| weighted avg | 0.911246 | 0.910317 | 0.910265 | 69623 |
|
| 269 |
+
|
| 270 |
+
</details>
|
config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"sklearn": {
|
| 3 |
+
"environment": [
|
| 4 |
+
"scikit-learn=1.4.2",
|
| 5 |
+
"xgboost=2.0.3"
|
| 6 |
+
],
|
| 7 |
+
"example_input": {
|
| 8 |
+
"data": [
|
| 9 |
+
"I Don't know?7? Months self harm free and the urge just gets stronger and stronger every day. The past few days I've just been shit... \nMy family stresses me out especially my nephew (he's 12) My mum has full custody of him and he's told me to go kill myself numerous times.. I wish it was that easy.\nMy partners family stresses me out especially over the past few days. \nStress is my trigger \nI just want to scream and cry. \nI live near the woods so I could go out and scream till I can't possibly scream anymore but the cops will probably get called...\nMy OH knows about my depression but he doesn't really know how I'm feeling at the moment. He would want to come over and make sure I'm OK but he's fucking annoying. He annoys me all the time by doing small stupid things. \nI don't even know where I'm going with the post? \n\n",
|
| 10 |
+
"I HAVE TO START BECOMING RICH I HAVE TO START MY COMPANY SO WHEN I BECOME 16 I CAN AFFORD A BIG VAN AND GO ON TRIPS WITH MY FRIENDS BUT I HAVE NO TIME LEFT I HAVE TO START WORKING",
|
| 11 |
+
"A poem (haiku) for u/Me-Game-Dev hi, hello hello\nstop fucking saying hello\ni know where you live"
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
"model": {
|
| 15 |
+
"file": "model.pkl"
|
| 16 |
+
},
|
| 17 |
+
"model_format": "pickle",
|
| 18 |
+
"task": "text-classification",
|
| 19 |
+
"use_intelex": false
|
| 20 |
+
}
|
| 21 |
+
}
|
confusion_matrix.png
ADDED
|
main.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sklearn
|
| 3 |
+
import xgboost
|
| 4 |
+
|
| 5 |
+
import dill as pickle
|
| 6 |
+
import pandas as pd
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
from sklearn.model_selection import train_test_split
|
| 10 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 11 |
+
from sklearn.pipeline import Pipeline
|
| 12 |
+
from sklearn.metrics import classification_report, f1_score, accuracy_score, roc_auc_score, RocCurveDisplay, roc_curve, auc, confusion_matrix, ConfusionMatrixDisplay
|
| 13 |
+
|
| 14 |
+
from skops import hub_utils
|
| 15 |
+
from skops import card
|
| 16 |
+
|
| 17 |
+
# load in in the Suicide Detection dataset
|
| 18 |
+
# accessible at https://www.kaggle.com/datasets/nikhileswarkomati/suicide-watch
|
| 19 |
+
df = pd.read_csv(
|
| 20 |
+
"Suicide_Detection.csv",
|
| 21 |
+
usecols=["text", "class"],
|
| 22 |
+
dtype= {"text":str,"class":str}
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# separate text and target class
|
| 26 |
+
X = df['text'].to_list()
|
| 27 |
+
y = df['class'].apply(lambda x: 1 if x == 'suicide' else 0).to_list()
|
| 28 |
+
|
| 29 |
+
# construct training and testing splits
|
| 30 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def preprocessor(s):
|
| 34 |
+
"""preprocessor for the tfidf vectorizer"""
|
| 35 |
+
|
| 36 |
+
from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS
|
| 37 |
+
|
| 38 |
+
stopwords_set = set(ENGLISH_STOP_WORDS)
|
| 39 |
+
|
| 40 |
+
def filter(text):
|
| 41 |
+
if text == None:
|
| 42 |
+
return ""
|
| 43 |
+
words = str(text).split()
|
| 44 |
+
filtered_words = [word for word in words if word and word.lower() not in stopwords_set]
|
| 45 |
+
return " ".join(filtered_words)
|
| 46 |
+
|
| 47 |
+
return filter(s)
|
| 48 |
+
|
| 49 |
+
# construct the model pipeline
|
| 50 |
+
model = Pipeline([
|
| 51 |
+
('tfidf', TfidfVectorizer(preprocessor=preprocessor, ngram_range=(1, 3), min_df=100)),
|
| 52 |
+
('classifier', xgboost.XGBClassifier())
|
| 53 |
+
], verbose=True)
|
| 54 |
+
|
| 55 |
+
# fit the model using the training split
|
| 56 |
+
model.fit(X_train, y_train)
|
| 57 |
+
|
| 58 |
+
# use the trained model to make predictions on the testing set
|
| 59 |
+
y_pred = model.predict(X_test)
|
| 60 |
+
y_pred_proba = model.predict_proba(X_test)[:, 1]
|
| 61 |
+
|
| 62 |
+
# save the trained model
|
| 63 |
+
model_filename = "model.pkl"
|
| 64 |
+
with open(model_filename, mode="bw") as f:
|
| 65 |
+
pickle.dump(model, file=f)
|
| 66 |
+
|
| 67 |
+
local_repo = Path("suicide-detector")
|
| 68 |
+
|
| 69 |
+
# construct the hugging face page
|
| 70 |
+
hub_utils.init(
|
| 71 |
+
model=model_filename,
|
| 72 |
+
requirements=[f"scikit-learn={sklearn.__version__}", f"xgboost={xgboost.__version__}"],
|
| 73 |
+
dst=str(local_repo),
|
| 74 |
+
task="text-classification",
|
| 75 |
+
data=X_test,
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
# made a header card from the metadata
|
| 79 |
+
model_card = card.Card(model, metadata=card.metadata_from_config(local_repo))
|
| 80 |
+
|
| 81 |
+
# add license
|
| 82 |
+
model_card.metadata.license = "mit"
|
| 83 |
+
|
| 84 |
+
model_description = """
|
| 85 |
+
Suicide Detection text classification model.
|
| 86 |
+
|
| 87 |
+
Trained on the Suicide and Depression Detection dataset (https://www.kaggle.com/datasets/nikhileswarkomati/suicide-watch)
|
| 88 |
+
|
| 89 |
+
The model vectorises each text using a trained tfidf vectorizer and then classifies using xgboost.
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
+
get_started_code = """
|
| 93 |
+
import sklearn
|
| 94 |
+
import dill as pickle
|
| 95 |
+
|
| 96 |
+
from skops import hub_utils
|
| 97 |
+
from pathlib import Path
|
| 98 |
+
|
| 99 |
+
suicide_detector_repo = Path("./suicide-detector")
|
| 100 |
+
|
| 101 |
+
hub_utils.download(
|
| 102 |
+
repo_id="AndyJamesTurner/suicideDetector",
|
| 103 |
+
dst=suicide_detector_repo
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
with open(suicide_detector_repo / "model.pkl", 'rb') as file:
|
| 107 |
+
clf = pickle.load(file)
|
| 108 |
+
|
| 109 |
+
classification = clf.predict(["I want to kill myself"])[0]
|
| 110 |
+
"""
|
| 111 |
+
|
| 112 |
+
# add additional details to the page including
|
| 113 |
+
# model description, getting started guide, and author
|
| 114 |
+
model_card.add(
|
| 115 |
+
get_started_code=get_started_code,
|
| 116 |
+
model_card_authors="Andy Turner",
|
| 117 |
+
model_description=model_description,
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
# add description of how the model was evaluated
|
| 121 |
+
eval_descr = (
|
| 122 |
+
"The model was evaluated on a 0.3 holdout split using f1 score, accuracy, confusion matrix and ROC curves."
|
| 123 |
+
)
|
| 124 |
+
model_card.add(eval_method=eval_descr)
|
| 125 |
+
|
| 126 |
+
# compute model evaluation metrics and add details to the hugging face model card
|
| 127 |
+
accuracy = accuracy_score(y_test, y_pred)
|
| 128 |
+
f1 = f1_score(y_test, y_pred, average="micro")
|
| 129 |
+
model_card.add_metrics(**{"accuracy": accuracy, "f1 score": f1})
|
| 130 |
+
|
| 131 |
+
cm = confusion_matrix(y_test, y_pred, labels=model.classes_)
|
| 132 |
+
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=model.classes_)
|
| 133 |
+
disp.plot()
|
| 134 |
+
disp.figure_.savefig(local_repo / "confusion_matrix.png")
|
| 135 |
+
model_card.add_plot(**{"Confusion matrix": "confusion_matrix.png"})
|
| 136 |
+
|
| 137 |
+
fpr, tpr, thresholds = roc_curve(y_test, y_pred_proba)
|
| 138 |
+
roc_auc = auc(fpr, tpr)
|
| 139 |
+
disp = RocCurveDisplay(fpr=fpr, tpr=tpr, roc_auc=roc_auc)
|
| 140 |
+
disp.plot()
|
| 141 |
+
disp.figure_.savefig(local_repo / "roc_curve.png")
|
| 142 |
+
model_card.add_plot(**{"ROC Curve": "roc_curve.png"})
|
| 143 |
+
|
| 144 |
+
clf_report = classification_report(
|
| 145 |
+
y_test, y_pred, output_dict=True, target_names=["not suicide", "suicide"]
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
del clf_report["accuracy"]
|
| 149 |
+
clf_report = pd.DataFrame(clf_report).T.reset_index()
|
| 150 |
+
model_card.add_table(
|
| 151 |
+
folded=True,
|
| 152 |
+
**{
|
| 153 |
+
"Classification Report": clf_report,
|
| 154 |
+
},
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
# construct a readme from the model card
|
| 158 |
+
model_card.save(local_repo / "README.md")
|
| 159 |
+
|
| 160 |
+
# add this file to the repo to document how it was constructed
|
| 161 |
+
hub_utils.add_files(
|
| 162 |
+
os.path.realpath(__file__),
|
| 163 |
+
dst=str(local_repo),
|
| 164 |
+
)
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b9bd700bdb9f7477e1a766c32c2877caa05cab6cd6aa9cb48bca65ad4d757dda
|
| 3 |
+
size 222084873
|
roc_curve.png
ADDED
|