Mercurial > hg > nsaunier > traffic-intelligence
comparison python/utils.py @ 840:15a82ebc62c4
utils for sparse matrix
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 08 Jul 2016 11:41:29 -0400 |
| parents | e01cabca4c55 |
| children | 90b7d6e19c55 |
comparison
equal
deleted
inserted
replaced
| 839:2c7b4e6a32dd | 840:15a82ebc62c4 |
|---|---|
| 5 import matplotlib.pyplot as plt | 5 import matplotlib.pyplot as plt |
| 6 from datetime import time, datetime | 6 from datetime import time, datetime |
| 7 from math import sqrt, ceil, floor | 7 from math import sqrt, ceil, floor |
| 8 from scipy.stats import kruskal, shapiro | 8 from scipy.stats import kruskal, shapiro |
| 9 from scipy.spatial import distance | 9 from scipy.spatial import distance |
| 10 from numpy import zeros, array, exp, sum as npsum, int as npint, arange, cumsum, median, isnan, ones, convolve, dtype, isnan, NaN, mean, ma, isinf | 10 from scipy.sparse import dok_matrix |
| 11 from numpy import zeros, array, exp, sum as npsum, int as npint, arange, cumsum, median, isnan, ones, convolve, dtype, isnan, NaN, mean, ma, isinf, savez, load as npload | |
| 11 | 12 |
| 12 | 13 |
| 13 datetimeFormat = "%Y-%m-%d %H:%M:%S" | 14 datetimeFormat = "%Y-%m-%d %H:%M:%S" |
| 14 | 15 |
| 15 ######################### | 16 ######################### |
| 481 table2['Variables'] = [var for var in result if data.dtypes[var] != dtype('O')] | 482 table2['Variables'] = [var for var in result if data.dtypes[var] != dtype('O')] |
| 482 out.write(DataFrame(table2)[['Variables', 'Correlations', 'Valeurs p']].to_html(formatters = {'Correlations': lambda x: '{:.2f}'.format(x), 'Valeurs p': lambda x: '{:.3f}'.format(x)}, index = False)) | 483 out.write(DataFrame(table2)[['Variables', 'Correlations', 'Valeurs p']].to_html(formatters = {'Correlations': lambda x: '{:.2f}'.format(x), 'Valeurs p': lambda x: '{:.3f}'.format(x)}, index = False)) |
| 483 out.close() | 484 out.close() |
| 484 return result | 485 return result |
| 485 | 486 |
| 487 def saveDokMatrix(filename, m): | |
| 488 'Saves a dok_matrix using savez' | |
| 489 savez(filename, shape = m.shape, keys = m.keys(), values = m.values()) | |
| 490 | |
| 491 def loadDokMatrix(filename): | |
| 492 'Loads a dok_matrix saved using the above saveDokMatrix' | |
| 493 data = npload(filename) | |
| 494 m = dok_matrix(tuple(data['shape'])) | |
| 495 for k, v in zip(data['keys'], data['values']): | |
| 496 m[tuple(k)] = v | |
| 497 return m | |
| 486 | 498 |
| 487 ######################### | 499 ######################### |
| 488 # regression analysis using statsmodels (and pandas) | 500 # regression analysis using statsmodels (and pandas) |
| 489 ######################### | 501 ######################### |
| 490 | 502 |
