gramex.ml
¶
Classifier(kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
data to train / re-train the model with |
required |
model_class |
str
|
model class to use (default: |
required |
model_kwargs |
dict
|
kwargs to pass to model class constructor (defaults: |
required |
output |
str
|
output column name (default: last column in training data) |
required |
input |
list
|
input column names (default: all columns except |
required |
labels |
list
|
list of possible output values (default: unique |
required |
Source code in gramex\ml.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
train(data)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
data to train / re-train the model with |
required |
model_class |
str
|
model class to use (default: |
required |
model_kwargs |
dict
|
kwargs to pass to model class constructor (defaults: |
required |
output |
str
|
output column name (default: last column in training data) |
required |
input |
list
|
input column names (default: all columns except |
required |
labels |
list
|
list of possible output values (default: unique |
required |
Notes: - If model has already been trained, extend the model. Else create it
Source code in gramex\ml.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
predict(data)
¶
Return a Series that has the results of the classification of data
Source code in gramex\ml.py
98 99 100 101 102 103 104 105 106 |
|
save(path)
¶
Serializes the model and associated parameters
Source code in gramex\ml.py
108 109 110 111 112 |
|
r(code=None, path=None, rel=True, conda=True, convert=True, repo='https://cran.r-project.org/', kwargs)
¶
Runs the R script and returns the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code |
str
|
R code to execute. |
None
|
path |
str
|
R script path. Cannot be used if code is specified |
None
|
rel |
bool
|
True treats path as relative to the caller function’s file |
True
|
conda |
bool
|
True overrides R_HOME to use the Conda R |
True
|
convert |
bool
|
True converts R objects to Pandas and vice versa |
True
|
repo |
str
|
CRAN repo URL |
'https://cran.r-project.org/'
|
All other keyword arguments as passed as parameters
Source code in gramex\ml.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
groupmeans(data, groups, numbers, cutoff=0.01, quantile=0.95, minsize=None, weight=None)
¶
DEPRECATED. Use TopCause() instead.
Yields the significant differences in average between every pair of groups and numbers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
pd.DataFrame
|
pandas.DataFrame to analyze |
required |
groups |
list
|
category column names to group data by |
required |
numbers |
list
|
numeric column names in to summarize data by |
required |
cutoff |
float
|
ignore anything with prob > cutoff. cutoff=None ignores significance checks, speeding it up a LOT. |
0.01
|
float |
quantile
|
number that represents target improvement. Defaults to .95.
The |
required |
int |
minsize
|
each group should contain at least minsize values. If minsize=None, automatically set the minimum size to 1% of the dataset, or 10, whichever is larger. |
required |
Source code in gramex\ml.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
weighted_avg(data, numeric_cols, weight)
¶
Computes weighted average for specificied columns
Source code in gramex\ml.py
288 289 290 291 292 293 |
|
translate(q, source=None, target=None, key=None, cache=None, api='google', kwargs)
¶
Translate strings using the Google Translate API.
translate('Hello', 'World', source='en', target='de', key='...')
returns a DataFrame
source target q t
en de Hello ...
en de World ...
The results can be cached via a cache={...}
that has parameters for
[gramex.data.filter]. Example:
translate('Hello', key='...', cache={'url': 'translate.xlsx'})
Parameters:
Name | Type | Description | Default |
---|---|---|---|
q |
str
|
one or more strings to translate |
()
|
source |
str
|
2-letter source language (e.g. en, fr, es, hi, cn, etc). |
None
|
target |
str
|
2-letter target language (e.g. en, fr, es, hi, cn, etc). |
None
|
key |
str
|
Google Translate API key |
None
|
cache |
dict
|
kwargs for [gramex.data.filter]. Has keys such as url (required), table (for databases), sheet_name (for Excel), etc. |
None
|
Reference: https://cloud.google.com/translate/docs/apis
Source code in gramex\ml.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
languagetoolrequest(text, lang='en-us', kwargs)
¶
Check grammar by making a request to the LanguageTool server.
Parameters¶
str
Text to check
str, optional
Language. See a list of supported languages here: https://languagetool.org/api/v2/languages
Source code in gramex\ml.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
|