def alert(duration=2): """ makes sound on client using javascript (works with remote server) """ framerate = 44100 freq=300 t = np.linspace(0,duration,framerate*duration) data = np.sin(2*np.pi*freq*t) d(Audio(data,rate=framerate, autoplay=True)) d(HTML("<style>audio{display:none}</style>"))
def alert(): """ makes sound on client using javascript (works with remote server) """ framerate = 44100 duration = .05 freq = 300 t = np.linspace(0, duration, framerate * duration) data = np.sin(2 * np.pi * freq * t) d(Audio(data, rate=framerate, autoplay=True))
def playSoundOnColab(): print("Colab plays sound") # Create a sound framerate = 44100 t = np.linspace(0,5,framerate*5) data = np.sin(2*np.pi*220*t) + np.sin(2*np.pi*224*t) # Generate a player for mono sound d(Audio(data,rate=framerate, autoplay=True))
def alert(): """ makes sound using javascript works on any os and on local notebook with remote kernel """ framerate = 44100 duration=.05 freq=300 t = np.linspace(0,duration,framerate*duration) data = np.sin(2*np.pi*freq*t) d(Audio(data,rate=framerate, autoplay=True)) # hide the audio control d(HTML("<style>audio{display:none}</style>"))
def stable(*args, **kwargs): """ survival table showing counts and %lived args[0] is row target died/lived args[1] is list of column variables """ # enable assign to args args = list(args) # if args[1] is single column then make it a list if not isinstance(args[1], list): args[1] = [args[1]] title = ", ".join([col.name for col in args[1]]) d(HTML("<h4>%s</h4>"%title)) table = pd.crosstab(*args, **kwargs) table.index = ["died", "lived"] table.loc["rate"] = table.iloc[-1] / table.sum() ftable = table.style.format("{:.0%}", subset=pd.IndexSlice["rate",:]) d(ftable)
def optimise(self, num_evals, target=None, search_space=None, verbose=20, metrics=["score"], **params): """ optimises score returned from target verbose 0=no output 10=score and charts on completion 20=score every iteration """ # set defaults if not target: target = self._target_crossval if not search_space: search_space = get_search_space(self.clf) # optimize o = Optuner() runs = o.maximise(target, search_space, num_evals=num_evals, verbose=verbose, **params) best_run = runs.get_best() best_params = runs.get_best_params() self.clf.set_params(**best_params) # report if verbose >= 10: clear_output() # best run best_params = ', '.join("{!s}={!r}".format(k,v) for (k,v) in best_params.items()) print("Best model:\n%s\n%s"%(best_run["clf"], best_params)) print("CV=%s TT=%s"%(best_run["score"], self.score())) # plots for metric in metrics: d(HTML("<h6>%s %s</>"%(best_run["clf"], metric))) runs.plot(metric)
def wide(): """ makes notebook fill screen width """ d(HTML("<style>.container { width:100% !important; }</style>"))
def hide_audio(): """ hide the audio control """ d(HTML("<style>audio{display:none}</style>"))